Business Rule Not Triggering When Value of String Field Changes to Required String
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2025 06:37 AM - edited 03-17-2025 08:02 AM
Version is Xanadu. I have a business rule on my x_1234_dlr_reemplo_third_party_admin_request table:
When Approval column value changed to be "Approved" this should trigger the business rule. However, I am not seeing proof of execution. This has the "Advanced" setting checked, so I also run a script:
(function executeRule(current, previous /*null when async*/ ) {
var fein = current.fein;
var randomNumber = Math.floor(Math.Random() * 90000000) + 10000000;
var pin = randomNumber.toString();
current.pin = pin;
current.update();
gs.info('Business Rule TPA_Approved_Generate_Pin. Pin: ' + pin + ". FEIN: " + fein);
var grEmployer = new GlideRecord('x_1234_dlr_reemplo_employer');
grEmployer.addQuery('fein', current.fein);
grEmployer.query();
if (grEmployer.next()) {
grEmployer.third_party_admin_request_pending = false; // Set to false
grEmployer.third_party_administrator_approved = true; // Set to true
grEmployer.pin = pin;
grEmployer.update();
}
})(current, previous);
My table, x_1234_dlr_reemplo_third_party_admin_request, also has a field named pin, which I am attempting to create a random 8 digit pin for, however, this NEVER gets updated after the record changes to an "Approved" state. I don't see any relevant logs that would indicate this even attempted to run.
The business rule should run whenever a record's "Approval" field changes to "Approved". I have also tried running "After" "Update" and that didn't work either.
Here is an example, viewing the list of the table records, changing the record to "Approved". Nothing happens:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2025 11:14 AM
Looks like you are missing a checkbox next to Update on your business rule! You need to signal that this business rule should fire after the update is committed to the database.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2025 11:22 AM
I have already tried that and it did not work. I believe it was because I was navigating to the table.list and "updating" / editing the record there.
When I navigate to the Workspace that shows the Request, and edit it there, an "update" message actually shows up on screen. And, subsequently, I can see the expected changes from the code/script. So, it probably is due to my understanding of what ServiceNow is considering an update. My initial impression was, this would include updating a value from tableName.list however this does not appear to be the case.
Changing from here allowed me to see my script actually execute, it failed due to syntax error which is now corrected. Math.Random() should have been Math.random().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2025 11:24 AM
Adding on to what I said: I should say that, yes, that does need to be checked. But, when I was trying to trigger the BR originally, my method of triggering it wasn't being seen as an Update on that record. So while, yes, you are right, I think that the issue I was having was related to what I just explained above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2025 11:25 AM
Interesting. I share the same understanding that a list edit qualifies. Are you certain you saved the record (e.g. clicked the green check mark when editing from list view)? You would need to refresh the page to see the data appear in your columns (at least on the classic list view; I'm not sure about in Workspace).