- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2023 07:26 PM - edited 09-27-2023 07:26 PM
Hi All,
I have below requirement:
All Tasks are Closed Complete – RITM and Request Closed Complete.
All Tasks are Closed Incomplete – RITM and Request Closed Incomplete.
All Tasks are Closed Skipped – RITM and Request Closed Skipped.
If it is a mix, then:
If any are Closed Complete, then RITM and Request Closed Complete
Else RITM and Request Closed Incomplete
I tried to do with Flow designer but it is updating only one state i.e Closed Complete
Please help me in the above logics in FD or with any script.
Thanks,
Samiksha
Solved! Go to Solution.
- Labels:
-
Service Catalog
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2023 11:20 PM
@Samiksha2 create another variable called "anyClosed" and in the for each step add an if condition, if task status is closed complete set anyClosed variable to true.
Then after the for loop your conditions will be like below,
if - anyClosed :: is :: true -- Set the status to Closed Complete
else if - first variable :: is :: closed complete -- Set the status to Closed Complete
else if - first variable :: is :: closed Incomplete -- Set the status to Closed Incomplete
else if- first variable :: is :: closed skipped -- Set the status to Closed Skipped
Please mark my answer helpful and accept as solution if it helped you 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 12:48 PM
Hey @Samiksha2
Will the BR work for what you asked for in the condition below because I have the same requirement?
"If it is a mix, then:
If any are Closed Complete, then RITM and Request Closed Complete
Else RITM and Request Closed Incomplete"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 11:17 PM
Hi @elphilli,
Create another BR on After update and state changes.
(function executeRule(current, previous /*null when async*/ ) {
var grSCTask = new GlideRecord('sc_task');
grSCTask.addQuery('request_item', current.getValue('request_item'));
grSCTask.addActiveQuery(); // added to check for active tasks
grSCTask.query();
if (!grSCTask.hasNext())
{
var closeCompleteCount = 0;
var closeSkippedCount = 0;
var closedIncompleteCount = 0;
var closedOtherCount = 0;
grSCTask = new GlideRecord('sc_task');
grSCTask.addQuery('request_item', current.getValue('request_item'));
grSCTask.query();
while (grSCTask.next()) {
if (grSCTask.getValue('state') == 3) {
closeCompleteCount++;
} else if (grSCTask.getValue('state') == 4) {
closedIncompleteCount++;
} else if (grSCTask.getValue('state') == 7) {
closeSkippedCount++;
} else {
closedOtherCount++;
}
}
var ritm = new GlideRecord('sc_req_item');
//var req = ritm.request.getRefRecord();
if (ritm.get(current.getValue('request_item'))) {
// if (closedIncompleteCount > 0 && closeCompleteCount == 0 && closedIncompleteCount == 0) {
// ritm.setValue('state', 4); // ritm is closed incomplete
// ritm.stage = "closed_incomplete";
// ritm.update();
// }
if (closeSkippedCount > 0 && closeCompleteCount == 0 && closedIncompleteCount == 0) {
ritm.setValue('state', 7); // ritm is closed skipped
// req.state = 7;
ritm.stage = "closed_incomplete";
ritm.update();
} else if (closeCompleteCount > 0 && closeSkippedCount == 0 && closedIncompleteCount == 0) {
ritm.setValue('state', 3); // ritm is closed complete
//req.state = 3;
ritm.stage = "Completed";
ritm.update();
} else if (closeCompleteCount > 0 && closeSkippedCount > 0) {
ritm.setValue('state', 3); // ritm is closed complete
//req.state = 3;
ritm.stage = "Completed";
ritm.update();
} else if (closeCompleteCount > 0 && closedIncompleteCount > 0) {
ritm.setValue('state', 3); // ritm is closed complete
//req.state = 3;
ritm.stage = "Completed";
ritm.update();
} else if (closeSkippedCount > 0 && closedIncompleteCount > 0 && closeCompleteCount == 0) {
ritm.setValue('state', 4); // ritm is closed complete
// req.state = 4;
ritm.stage = "closed_incomplete";
ritm.update();
}
}
}
})(current, previous);
Hope this will work.
Thanks,
Samiksha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 01:07 PM
Hey, I have tried the BR above and that did not resolve the mixture of SCTASKs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 08:39 PM
Hi @elphilli ,
It should work. Can you please show me your BR. I hope you have created two BRs.
Thanks,
Sam