Business rule not working when inserting a record via REST API process

carlh
Kilo Guru

Good morning.   I need a script tweak...

I have a BEFORE Business Rule that is setting the value of Date field as a Time Stamp

find_real_file.png

find_real_file.png

Here's the script that runs when it meets this condition.

(function executeRule(current, previous /*null when async*/) {

var now = new GlideDateTime();

current.u_inshold_glide_date = now;

})(current, previous);

This is working great when I update a record.

But, now we're inserting new records in our nightly process and I have another rule that is setting the "Insurance Hold?" to true on "Insert".   That worked over night but it did not set the "Insurance Hold Date" as it does when I update.   Then I went in to update and nothing changed.

Here's my question.   If I just make "Insert = True" on the business rule above, and change the condition to IS True rather than "CHANGES To True"   will it fix my issue?

The purpose of this is to put newly Inserted vendors on Insurance hold until someone has an opportunity to review their insurance documents.

What do you suggest?

6 REPLIES 6

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Carl,



Can you replace line current.u_inshold_glide_date = now; to current.u_inshold_glide_date = gs.now;


Also make sure insert is set to true and give order value higher for this rule.


Thanks Pradeep.   Nothing happened after making the suggested changes.



I checked INSERT


Changed the order to 200


And added the "gs.now" as shown below




(function executeRule(current, previous /*null when async*/) {


var now = new GlideDateTime();


current.u_inshold_glide_date = gs.now;


})(current, previous);


mrswann
Kilo Guru

I'm having a similar issue.



We have some business rules, such as Company Projection which has order 100



When an incident is inserted via an external REST message, this business rule does not run