- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2017 10:26 PM
Can you please help me with this.
The problem should not be closed/resolved unless the problem task is closed.
i had written a before business rule(update)
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('problem_task');
gr.addQuery('active','true');
gr.addQuery('problem',current.sys_id);
gr.query();
if (gr.next()) {
current.setAbortAction(true);
}
})(current, previous);
though i am getting the message as invalid update but the state is changing to Closed/Resolved.
and also i want to display an alert message for the user saying that problem task is not closed.
Can anyone please help me.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2017 10:43 PM
Hi Naveen,
The Script you have written is perfectly fine, I believe. Please try to reload the form when the 'Invalid Update' comes up. Because the form is not saved and it remains the previous state actually.
Also from Server Side Script you can not use alert message, but you can use AddInfoMessage (for details Scripting Alert, Info, and Error Messages - ServiceNow Wiki). Please use the below script:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('problem_task');
gr.addActiveQuery();
gr.addQuery('problem',current.sys_id);
gr.query();
if (gr.next()) {
gs.addInfoMessage('Please close the related Problem tasks first.');
current.setAbortAction(true);
}
})(current, previous);
I hope this helps.Please mark correct/helpful based on impact

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2017 10:38 PM
Hi Naveen,
You can add current.state=previous.state before current.setAbortAction(true) inside if condition.
Regards,
Ujjawal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2017 10:48 PM
Thanks for the reply but i dont know for some reason it s not setting the state value to previous value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2017 10:57 PM
There may be some other business rule, changing the value of state. Also check, if there is any client script changing the value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2017 10:43 PM
Hi Naveen,
The Script you have written is perfectly fine, I believe. Please try to reload the form when the 'Invalid Update' comes up. Because the form is not saved and it remains the previous state actually.
Also from Server Side Script you can not use alert message, but you can use AddInfoMessage (for details Scripting Alert, Info, and Error Messages - ServiceNow Wiki). Please use the below script:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('problem_task');
gr.addActiveQuery();
gr.addQuery('problem',current.sys_id);
gr.query();
if (gr.next()) {
gs.addInfoMessage('Please close the related Problem tasks first.');
current.setAbortAction(true);
}
})(current, previous);
I hope this helps.Please mark correct/helpful based on impact