Update SCTASK state change to RITM & REQ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2024 09:52 PM
Hi Team ,
can anyone please help me on this requirment ,
whenever sctask state changes same should be refelected to ritm and req table ,
can any one please provide me the BR script ,
if possible please provide me the configuration screenshot for better understanding .
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2024 10:05 PM
Just do it from the flow. No need to script this. Just update the RITM/REQ when the SCTASK is updated.
But remember that RITMs can have multiple tasks, so you need to do a check to see if there aren't any other tasks still open.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2024 10:10 PM
But why? each table has it's own State and has it's own meaning.
You can use after update BR on sc_task, but remember state choice values might be different between sc_task, sc_req_item
After Update BR
Condition: State Changes
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ritmRec = current.request_item.getRefRecord();
ritmRec.state = current.state;
ritmRec.update();
var reqRec = current.request.getRefRecord();
reqRec.state = current.state;
reqRec.update();
})(current, previous);
Note: the above is just sample script, As mentioned earlier by me ensure you set correct states on RITM, REQ based on SC Task state
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
12-29-2024 10:26 PM
see SLA is not cancelling , i don't know what stoping here .
Thanks for quick help ,
There was Business rule configured on sc_task , and I am thinking because of that BR , SLA is delaying .
(function executeRule(current, previous /*null when async*/ ) { //Update RITM State var flag =0; var state=current.state; var gr = new GlideRecord("sc_task"); gr.addActiveQuery(); gr.addQuery("request_item", current.request_item); gr.query(); while (gr.next()) { state = gr.state; if(state !=3 || state !=4|| state !=7){ //gs.addErrorMessage("Please close the sc_tasks to proceed to Resolved state"); //current.setAbortAction(true); flag =1; break; }} var ritmst = new GlideRecord('sc_req_item'); ritmst.get(current.request_item); //Update ritm state similar to sctask //ritmst.stage = 'fulfillment'; // Update stage after SCTASK is reopened if (flag==0){ ritmst.state = current.state; ritmst.setWorkflow(false); ritmst.update(); ritmst.setWorkflow(true); } else { ritmst.state = state; ritmst.setWorkflow(false); ritmst.update(); ritmst.setWorkflow(true); } ritmst.update(); var reqstate = ritmst.state; //Update Request State var req = new GlideRecord('sc_request'); req.addQuery('sys_id', current.request); req.query(); while (req.next()) { req.state = reqstate; req.setWorkflow(false); req.update(); req.setWorkflow(true); if (reqstate == 3) req.stage = "closed_complete"; if (reqstate == 4) req.stage = "closed_incomplete"; if (reqstate == 7) req.stage = "closed_skipped"; req.setWorkflow(false); req.update(); req.setWorkflow(true); if (reqstate == 3) req.request_state = "closed_complete"; if (reqstate == 4) req.request_state = "closed_incomplete"; if (reqstate == 7) req.request_state = "closed_skipped"; req.setWorkflow(false); req.update(); req.setWorkflow(true); req.active = "false"; req.setValue("active", "false"); //req.setWorkflow(false); req.update(); //req.setWorkflow(true); } })(current, previous);
There was more setworkflow was written because of that i think issue is happening ,
could you please provide me the correct or updated script so that i can update .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2024 10:13 PM
To sync SCTASK state with RITM and REQ tables, create a Business Rule triggered by state changes. Use a script to update the state in both RITM and REQ records. Test to ensure the synchronization works correctly!