- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2021 06:07 PM
Hi all,
I currently have a flow via Flow Designer where if a service catalog item is ordered it will kick off approvals and then create some tasks in relation to the requested item. If the tasks are closed the requested item (RITM) is also Closed Complete, Closed Incomplete, however, the REQ still remains open.
Are there any business rule scrips I can apply to force the REQ state and also requested state to Closed Complete/Closed Incomplete if all RITMs are Closed Complete/Closed Incomplete.
Thank you for your help!
Solved! Go to Solution.
- Labels:
-
Request Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2021 07:18 PM
Hi Omer,
yes, there is a Business Rules "Close parent if required" on RITM table which examines more the stage field values rather than state.
function closeParentIfRequired() {
// check to see if any of our peers are currently *not* closed
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.request);
gr.addQuery('stage', '!=', 'complete');
gr.addQuery('stage', '!=', 'closed_skipped');
gr.addQuery('stage', '!=', 'closed_incomplete');
gr.addQuery('stage', '!=', 'Request Cancelled');
gr.query();
if (!gr.next()) {
// no peer task is currently open
gr.initialize();
gr.addQuery('request', current.request);
gr.query();
var ritmCount = gr.getRowCount();
var stage = 'closed_complete';
var incomplete = 0;
var skipped = 0;
while (gr.next()) {
if (gr.getValue('stage') == 'closed_incomplete' || gr.getValue('stage') == 'Request Cancelled') {
stage = gr.getValue('stage');
incomplete++;
break;
} else if (gr.getValue('stage') == 'closed_skipped') {
skipped++;
}
}
var sc_request = new GlideRecord('sc_request');
sc_request.addQuery('sys_id', current.request);
sc_request.query();
sc_request.next();
gs.debug("SC_REQUEST.STAGE = " + sc_request.stage + " INDEX = " + sc_request.stage.toString().indexOf('closed'));
if (sc_request.stage.toString().indexOf('closed') == -1) {
if (incomplete)
stage = 'closed_incomplete';
if (skipped == ritmCount)
stage = 'closed_skipped';
sc_request.stage = stage;
sc_request.comments.setJournalEntry("Request Automatically Closed as all Line Items were complete");
sc_request.update();
}
}
}
Therefore, make sure, that you have added the respective stages to your flow. If not possible you have to close the Request by your own (what I sometimes also do)
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2021 07:18 PM
Hi Omer,
yes, there is a Business Rules "Close parent if required" on RITM table which examines more the stage field values rather than state.
function closeParentIfRequired() {
// check to see if any of our peers are currently *not* closed
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.request);
gr.addQuery('stage', '!=', 'complete');
gr.addQuery('stage', '!=', 'closed_skipped');
gr.addQuery('stage', '!=', 'closed_incomplete');
gr.addQuery('stage', '!=', 'Request Cancelled');
gr.query();
if (!gr.next()) {
// no peer task is currently open
gr.initialize();
gr.addQuery('request', current.request);
gr.query();
var ritmCount = gr.getRowCount();
var stage = 'closed_complete';
var incomplete = 0;
var skipped = 0;
while (gr.next()) {
if (gr.getValue('stage') == 'closed_incomplete' || gr.getValue('stage') == 'Request Cancelled') {
stage = gr.getValue('stage');
incomplete++;
break;
} else if (gr.getValue('stage') == 'closed_skipped') {
skipped++;
}
}
var sc_request = new GlideRecord('sc_request');
sc_request.addQuery('sys_id', current.request);
sc_request.query();
sc_request.next();
gs.debug("SC_REQUEST.STAGE = " + sc_request.stage + " INDEX = " + sc_request.stage.toString().indexOf('closed'));
if (sc_request.stage.toString().indexOf('closed') == -1) {
if (incomplete)
stage = 'closed_incomplete';
if (skipped == ritmCount)
stage = 'closed_skipped';
sc_request.stage = stage;
sc_request.comments.setJournalEntry("Request Automatically Closed as all Line Items were complete");
sc_request.update();
}
}
}
Therefore, make sure, that you have added the respective stages to your flow. If not possible you have to close the Request by your own (what I sometimes also do)
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2021 07:39 PM
Hi Maik,
Thank you for getting back to me. This script does not work with my workflow as I have different different stages which do not match the out of the box script. Do you know of any business rule scripts that uses 'State' rather than 'Stage'?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2023 01:48 AM
Hello,
I have requirement of if task is closed incomplete or closed skipped then RITM needs to be also closed incomplete or closed skipped. So, for that we have added Request cancelled stage in Flow but when stage is set to Request cancelled of RITM then the state is closed complete for task is closed incomplete or closed skipped also. We have to do it using flow stages only. So, is there any solution for that??
Is there any OOB for stage of RITM that if stage is Request cancelled then the state is Closed complete??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 05:10 PM
This solved our issue.