ServiceNow - Creating flash alerts using Business Rules

by
Jeremy Canfield |
Updated: February 09 2024
| ServiceNow articles
These are just my personal notes as I was working through the New to ServiceNow training modules.
By default, a record can be inserted into a table with a date in the past. In this example, a Business Rule will be created to display a flash message and to prevent the record from being inserted when a date in the past is used.
In All > Studio I selected my app (NeedIt) and then selected Server Development > Business Rule. I used the following to do something before inserting a record into the table.
And then used the following script on the Advanced tab.
var rightnow = new GlideDateTime();
// Create a GlideDateTime object for the When needed date
var whenNeeded = new GlideDateTime(current.u_when_needed);
// If the When needed date is before rightnow, do not write the record to the database
// Output an error message to the screen
if(whenNeeded.before(rightnow)){
gs.addErrorMessage("When needed date cannot be in the past. Your request has not been saved to the database.");
current.setAbortAction(true);
}
Then I tried to insert a record into the database with a date in the past and I got flash messages.
Did you find this article helpful?
If so, consider buying me a coffee over at