- 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 08:14 AM
Not sure what I am doing wrong. The code does not give expected results.
Business rule is on sc_req_item table
It's running before and on update
on line 5 I am calling sc_req_item table.
The results I get is that even RITM records with no catalog tasks gives error message
I appreciate your effort.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 08:16 AM
Hi Joyce,
line number 5 should be having request_item instead of sc_req_item in the addQuery()
that is because request_item is the field on sc_task which stores the RITM record
gr.addQuery('request_item', current.sys_id);
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 08:31 AM
I changed line 5. Thank you! That solves one problem- I can close items that have no task record.
Any item with task record still gets error even if the task is in closed Complete state
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 08:37 AM
Hi Joyce,
Does that task belong to this RITM?
Ideally it should not;
Example: if RITM has 2 task
1 task is complete and 1 is in progress the rowcount would be 1 so it would stop
if both the tasks are complete then the rowcount would be 0 so it would allow record to be saved
Regards
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 08:43 AM
Task belongs to the RITM record and both tasks are on complete state. Even where the task is single record, the RITM does not update
Is it possible to check for active flag on sc_task other than rowcount