- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 01:19 AM
required help @Vasantharajan N @Ankur Bawiskar
As I need to set the RITM & REQ state.
When the SCTASK state is "Closed Incomplete" then the RITM & REQ state needs to change to "Closed Incomplete".
Tried with below script in Business Rule.
Business Rule:
When : After (Update)
Table: sc_task
Script:
(function executeRule(current, previous /*null when async*/) {
var requestItem = current.getValue('request_item');
var closedCompleteSCTask = 0;
var closedSCTask = 0;
var scTask = new GlideRecord("sc_task");
scTask.addQuery("request_item", requestItem);
scTask.query();
var scTaskCount = scTask.getRowCount();
while (scTask.next()) {
var scTaskState = scTask.getValue('state');
if (scTaskState == 3) { // State is closed complete
closedCompleteSCTask++;
closedSCTask++;
}
if (scTaskState == 4) //State is closed incomplete
closedSCTask++;
}
if (closedSCTask == scTaskCount) {
if (closedCompleteWOT > 0)
closeRITM(3); // Set RITMstate = closed complete.
else
closeRITM(4); //Set RITM state = closed incomplete.
}
function closeRITM(state) {
var msg = '';
var ritmQuery = 'stateNOT IN3,4'; //State is not one of the Closed states
var requestItem = new GlideRecord('sc_req_item');
requestItem.addEncodedQuery(ritmQuery);
requestItem.addQuery('sys_id', wo);
requestItem.query();
if (requestItem.next()) {
requestItem.setValue('close_notes', msg);
requestItem.setValue('state', state);
requestItem.update();
}
}
})(current, previous);
SCTASK State Value:
RITM State Value:
But when the SCTASK state is "Closed Complete" then the RITM & REQ state changes to "Closed Complete" via workflow it's working as expectecd.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 03:17 AM
I got the solution after doing changes in workflow as well as UI Action
Workflow:
UI Action:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 02:15 AM
did you check logs on what came in counter for closed and closed incomplete?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 03:17 AM
I got the solution after doing changes in workflow as well as UI Action
Workflow:
UI Action: