current.update() not working in script action

Milan13
Giga Expert

Hello,

I have a script action which reacts to an event in a business rule, after this event is triggered I need certain fields to be updated, even if the script action reacts to the event according to log, "current" parameters are accessible within the script according to log, current.update() does not work for some reason...

Script action:

gs.log('!!!MILAN - STORY43....');
setFields();

function setFields() {

current.state = '9';
current.short_description = 'Test from script action';
current.assigned_to = "";
gs.info('!!!MILAN' + current.assigned_to + current.state + current.short_description);
current.update();

}

 

gs.info in log works with the correct values, however what does not work is the current.update() part as the data on the incident form do not get updated..

Any idea why?

Appreciate your help,

Milan

find_real_file.png

Log (gs.info('!!!MILAN' + current.assigned_to + current.state + current.short_description);

find_real_file.png

 

1 ACCEPTED SOLUTION

AbhishekGardade
Giga Sage

Hello Milan,

try out with below code:

var grIncident = new GlideRecord('incident');
grIncident.addQuery('sys_id',current.sys_id);
grIncident.query();
while(grIncident.next()){
grIncident.short_description = "Test from script action";
grIncident.setValue('assigned_to','');
grIncident.update();
}


Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

View solution in original post

14 REPLIES 14

Ahmmed Ali
Mega Sage

Can you show the code where you are triggering the event?

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

(function executeRule(current, previous /*null when async*/) {
gs.eventQueueScheduled('on.hold.reminder', current, 'parm1', 'parm2', current.u_on_hold_reminder);
})(current, previous);

 

But the event just gets triggered, the only issue is the update whc is not workig,

Thanks a lot,

Milan

try passing incident number or sys_id in parameter and in script action you can read the same parameter and query the incident table.

 

ex: gs.eventQueueScheduled('on.hold.reminder', current, current.sys_id, current.number, current.u_on_hold_reminder); 

 

in script action: IncidentGlideRecord.addQuery("sys_id",event.parm1);

or

IncidentGlideRecord.addQuery("number",event.parm2);

 

Thanks,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Andy9
Kilo Contributor

Hi Milan,

Can you possibly do one thing for me, go and try these things manually on the form.

Open the incident form and attempt to update a record using the above info ie update the short description and assigned to field.

Do you get prompted to enter information in a required field?

In this case you may need to account for mandatory fields requiring information

 

Kind Regards,

Andy

ARG645
Tera Guru

Using current.update() in an event is fine. But current.update() in an event, which inturn is triggered by a Business Rule may start recurring events. Where BR gets triggered due to an Update (1) then it produces an event which triggers another update (2), this update (3)will trigger the BR again ..........

ServiceNow has a monitoring mechanism (if thats what its called), which can detect these kind of continious loops and stops them from occuring. Please make sure you are not running into such loop. 

Thank you,

A.R.G.