Business Rule Not Triggering When Value of String Field Changes to Required String

ztb1997
Tera Contributor

Version is Xanadu. I have a business rule on my x_1234_dlr_reemplo_third_party_admin_request table:

ztb1997_0-1742218079256.png


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:

ztb1997_0-1742223714262.png

 

6 REPLIES 6

jcmings
Mega Sage

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.

 

jc21_0-1742235188946.png

 

ztb1997
Tera Contributor

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.

ztb1997_0-1742235710547.png


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().

ztb1997
Tera Contributor

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.

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).