- 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-20-2019 03:10 AM
It must work if you followed this : Create a simple reminder email
If possible can you give me access on your instance so I can check.
if yes. you can drop me mail on gardadeabhishek@gmail.com with instance id and credentials.
Thanks,
Abhishek
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2019 03:36 AM
I have sent you an e-mail a minute ago.
Appreciate your help,
Milan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2019 03:41 AM
Got it
Abhishek Gardade
- 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:49 PM
Hi Milan,
did you try to print the current.sys_id in the log to check if the same sys_id comes
also check the rowCount for the query
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader