- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 05:21 AM
I am new to scripting.
I want to have a business rule that prevents Requested Item record from closing if Catalog task is NOT in closed complete state
Thank you kindly,
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 09:56 AM
try this
var gr = new GlideRecord('sc_task');
gr.addQuery('requested_item', current.sys_id);
gr.addEncodeQuery('state=1^ORstate=2');
gr.addActiveQuery();
gr.query();
if (gr.next())
{
gs.addErrorMessage('There are open task records for this requested item. Please close all tasks.');
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 09:26 AM
Hi Joyce,
Can you share the screenshot here?
Also did you check what is the state value of those tasks?
yes you can query on active flag
whenever task is changed to complete active field is set to false
i.e. when state changes to either "Closed Complete" or "Closed Incomplete" or "Closed Skipped" active flag is set to false
update script as below; if any 1 open task found i.e. active task found then stop form submission
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.sys_id);
gr.addEncodedQuery('active=true');
gr.query();
if(gr.getRowCount() > 0){
gs.addErrorMessage('Please close all the open tasks to close the RITM');
current.setAbortAction(true);
}
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 09:56 AM
try this
var gr = new GlideRecord('sc_task');
gr.addQuery('requested_item', current.sys_id);
gr.addEncodeQuery('state=1^ORstate=2');
gr.addActiveQuery();
gr.query();
if (gr.next())
{
gs.addErrorMessage('There are open task records for this requested item. Please close all tasks.');
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 12:36 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 01:28 PM
getRowCount is really inefficient and I would not use it
if you want to get a row count consider glideAggregate
if you are looking to see if just there is more than one record then consider gr.setLimit(1)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2021 12:01 AM
Hi Ankur ,
gr.addQuery('request_item', current.sys_id);
Can you please tell me what is this "request_item" in the above code. I am not able to find any field on the RITM form with this name.
Thanks & Regards