- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2019 12:44 AM
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
Log (gs.info('!!!MILAN' + current.assigned_to + current.state + current.short_description);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2019 01:10 AM
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
Abhishek Gardade

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2019 01:25 AM
Can you show the code where you are triggering the event?
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2019 02:34 AM
(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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2019 02:43 AM
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
Thank you,
Ali

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2019 05:12 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2019 02:22 PM
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.