
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 02:00 AM
Hi Team,
I have a query I have written a before update BR, and I am comparing the date field. but I am getting the error message multiple times if the condition meets?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 02:05 AM
Hi @Community Alums ,
If multiple records are updating at a time then yes above error msg will show those many times.
thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 03:07 AM - edited 03-18-2024 03:46 AM
Hi @Ankur20,
A query business rule can legitimately be called multiple times meaning the message will appear (and be duplicated) each and everytime, however, a good way to make sure the cache is clear is to leverage the below syntax:
gs.flushMessages()
Call this before your gs.addErrorMessage() call.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 02:05 AM
Hi @Community Alums ,
If multiple records are updating at a time then yes above error msg will show those many times.
thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 02:08 AM
Hi @Community Alums,
A query business rule can legitimately be called multiple times, however, a good way to make sure the cache is clear is to leverage the below syntax:
gs.flushMessages()
Call this before your gs.addErrorMessage() call.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 02:53 AM
Hi @Community Alums
Here’s a revised version of your script with corrections:
(function executeRule(current, previous /null when async/) {
// Corrected variable declaration syntax and method name
var bed = new GlideDateTime(current.u_billing_effective_date); // Ensure the field name is correct
var fx_account_date = new GlideDateTime(current.account.u_fx_account_active_date); // Ensure the field name is correct
// Fixed comparison logic by using GlideDateTime comparison methods
if (bed.before(fx_account_date)) {
gs.addErrorMessage(“The Billing Effective Date may not predate the FX Account Active Date.”);
}
})(current, previous);
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help us a lot.
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 03:05 AM
Hi @Community Alums
It's likely because the Business Rule is running for each record updates. To prevent this, ensure that your condition is specific enough to only trigger the desired behavior. You can use following function-
flushMessages: function() {
gs.flushMessages();
}
It clears all messages stored in the GlideSystem message queue in ServiceNow, ensuring only the most relevant messages are displayed to the user.
Regards,
Amit