RITM needs to be close compley when the sc task are close complete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2025 07:20 AM
Hello All,
I am working on creating a business rule for the sctask table. The purpose is to close complete the RITM when all SCTasks are marked as "Closed Complete,".
I have written the following script, which works fine when all tasks are generated concurrently. However, it fails when tasks are generated sequentially, one after another. This happens because using "after update" or "before update" doesn't effectively handle tasks created at a later time.
var grScTask = new GlideRecord("sc_task");
grScTask.addQuery('request_item', current.request_item);
grScTask.addEncodedQuery("number!=" + current.number + '^state!=3');
grScTask.query();
var count = grScTask.getRowCount();
if (count == 0) {
var ritm = current.request_item.getRefRecord();
ritm.state = 3; // closed complete.
ritm.stage = 'complete';
ritm.update();
}
Does anyone have any idea
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2025 07:45 AM
BR should be after update
use this
var taskRec = new GlideRecord("sc_task");
taskRec.addEncodedQuery("request_item=" + current.request_item + "^active=true"); // if no active tasks for this RITM exists
if(!taskRec.hasNext()){
var ritm = new GlideRecord("sc_req_item");
if(ritm.get(current.request_item)){
ritm.state = 3;
ritm.update();
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2025 10:52 PM
Hello Ankur,
Thank you for your response,
I tried your Business Rule, but it is not working in the situation where the second task is generated after the first one is marked as 'Closed Complete.' I think the second task is being generated after the Business Rule executes.