Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Script Action is not triggering

KS86
Tera Contributor

I have created an event to trigger Script Action and I have mentioned event in Business rule. But script is not triggering so it is not updating records. 

I am writing script to update Network Adapters when Parent CI description is updated.

 

BR Script - 

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

    gs.addInfoMessage("Line 4");
    gs.eventQueue('update.cmdb_ci_adpaters.comments', current, previous.short_description, previous.dns_domain);

})(current, previous);
 
Script Action - 
var gr = new GlideRecord('cmdb_ci_network_adapter');
gr.addQuery('cmdb_ci', current.sys_id);
gr.query();
while (gr.next()) {
    gs.addInfoMessage("Previous Comments " + event.parm1 + "Previuos Domain " + event.parm2);
    gr.comments = "Parent CI desc updated as " + current.short_description;
}
Please refer attachments for more details - 
 
KS86_0-1745047503782.pngKS86_1-1745047525029.png

 

KS86_2-1745047557006.png

 

 
1 ACCEPTED SOLUTION

Robert H
Mega Sage

Hello @KS86 ,

 

You need to add "gr.update()" at the end of the while loop in the Script Action. This will save your updates.

 

...
while (gr.next()) {
    gr.comments = "Parent CI desc updated as " + current.short_description;
    gr.update();
}

 

Regards,

Robert

View solution in original post

3 REPLIES 3

Robert H
Mega Sage

Hello @KS86 ,

 

You need to add "gr.update()" at the end of the while loop in the Script Action. This will save your updates.

 

...
while (gr.next()) {
    gr.comments = "Parent CI desc updated as " + current.short_description;
    gr.update();
}

 

Regards,

Robert

Ankur Bawiskar
Tera Patron

@KS86 

is that event getting triggered and processed?

you forgot to include gr.update() as mentioned by @Robert H 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

J Siva
Kilo Patron

Hi @KS86 
Add gr.update() at the end of your script in the script action.

var gr = new GlideRecord('cmdb_ci_network_adapter');
gr.addQuery('cmdb_ci', current.sys_id);
gr.query();
while (gr.next()) {
    gs.addInfoMessage("Previous Comments " + event.parm1 + "Previuos Domain " + event.parm2);
    gr.comments = "Parent CI desc updated as " + current.short_description;
    gr.update();
}

Regards,
Siva