- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2019 09:56 PM
Hello,
I have a problem with script action which reacts to appropriate event, has access and can set up the "current" object, but does not update fields.
I have added some gs.log statements which show the code works partially apart of the current.update() part.
Can anyone please advise?
Many thanks,
Milan
My script action:
setFields();
function setFields() {
gs.info('!!!MILAN CURRENT STATES BEFORE SETTING THEM: ' + current.assigned_to + ' - ' + current.state + ' - ' + current.short_description);
current.state = '9';
current.short_description = 'Test from script action';
current.assigned_to = '';
gs.info('!!!MILAN CURRENT STATES AFTER SETTING THEM: ' + current.assigned_to + ' - ' + current.state + ' - ' + current.short_description);
try {
current.update();
}
catch(err) {
gs.error("UPDATE ERROR: " + err);
}
Log screen shot (not showing any update error so far..):
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2019 11:13 AM
Hello Milan,
Finally I got the issue and I have tested the functionality its working.
Here are my observations to find out the issue
1. Script action is running perfectly on time but due to another before business rule it is aborting the update.
2. To reproduce issue: comment out the line 5 and 6 as below:
var rec = new GlideRecord(current.sys_class_name);
rec.get(current.sys_id);
rec.state = '9';
//rec.setValue('hold_reason','');
//rec.setValue('u_on_hold_reminder','');
rec.short_description = 'Test from script action';
rec.assigned_to = '';
rec.update();
gs.log('!!!MILAN CURRENT STATES AFTER SETTING THEM: ' + current.assigned_to.name + ' - ' + current.state + ' - ' + current.short_description);
keep any incident on hold, save it and then try to changing state to on hold to in progress or another as you want and try to save. You will get below error (2 addInfoMessage):
invalid update()
On hold reminder datetime must be greater than current datetime.
3. So if you can check the business rule named "Story 130 Check On Hold Reminder".You just have added condtion on hold reminder is not empty and logic for validating date.
RESOULTION: You can choose one of the solution. I have modified the script action to just to achieve your need.
1. Add more condition in business rule :"Story 130 Check On Hold Reminder" like incident state is not pending. use changesFrom, changesTo if needed.
2. Why you have created 2 different business rule? you can merge both business rules and if validation is successful then trigger event else abort update with alert.
3. Modify script action as I did already.
Let me know if anything else is needed.
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-19-2019 11:13 PM
No it does not work, nor does it set the values before update (according to log).
Thanks a anyway.
Milan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2019 11:06 PM
Hello Milan,
Please check the domain of script action if you are working in domain separated instance.
Script Action must be in a global domain in order to run.
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-19-2019 11:15 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2019 11:41 PM
Can you share script from where you are calling the eventQueue?
Thanks,
Abhishek
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2019 02:36 AM
I can but I do not think its the reason as according to log it gets fired properly.
Business Rule:
(function executeRule(current, previous /*null when async*/) {
gs.eventQueueScheduled('on.hold.reminder', current, 'parm1', 'parm2', current.u_on_hold_reminder);
})(current, previous);