Reset flow related to RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 11:25 PM - edited 03-18-2025 11:30 PM
Hello mates,
i want to share this scenario which is working fine form me, if you have related query it would be helpful,
i have created a UI action to reset the flow related to RITM and approvals.
function checkOpen() {
var userConfirmation = confirm('Do you want to Reopen this RITM again?');
if (userConfirmation) {
gsftSubmit(null, g_form.getFormElement(), 'reopen_ritm');
}
}
if (typeof window == 'undefined') {
restartFlow();
}
function restartFlow() {
try {
// Reopen and update the parent request (REQ)
var reqRecord = new GlideRecord('sc_request');
if (reqRecord.get(current.request)) {
reqRecord.setWorkflow(false); // Prevent workflow triggers on update
reqRecord.request_state = 'requested'; // Set REQ to 'requested'
reqRecord.active = true;
reqRecord.update();
gs.info('Parent REQ reopened: ' + reqRecord.number);
// Restart traditional workflow for REQ
var wflow = new Workflow();
wflow.restartWorkflow(reqRecord);
wflow.runFlows(reqRecord, "update");
} else {
throw new Error('Unable to find parent request (REQ) for RITM: ' + current.number);
}
// Cancel all related approvals
var approvals = new GlideRecord('sysapproval_approver');
approvals.addQuery('sysapproval', current.sys_id.toString());
approvals.orderByDesc('sys_created_on');
approvals.query();
while (approvals.next()) {
approvals.state = 'cancelled';
approvals.update();
gs.info('Approval cancelled: ' + approvals.sys_id);
}
// Cancel existing flow contexts for the RITM
var grFlowContext = new GlideRecord('sys_flow_context');
grFlowContext.addQuery('source_record', current.sys_id.toString());
grFlowContext.orderByDesc('sys_created_on');
grFlowContext.query();
while (grFlowContext.next()) {
sn_fd.FlowAPI.cancel(grFlowContext.sys_id.toString(), 'cancel');
gs.info('Flow context cancelled: ' + grFlowContext.sys_id);
}
//Restart the Flow Designer flow for the RITM
var flow = current.cat_item.flow_designer_flow;
if (!flow) throw new Error('Flow Designer flow not found for RITM: ' + current.number);
var flowName = flow.sys_scope.scope + "." + flow.internal_name;
var inputs = { 'table_name': 'sc_req_item', 'request_item': current };
var contextId = sn_fd.FlowAPI.startFlow(flowName, inputs);
//Update RITM state and fields
current.state = '1'; // Set to 'Open'
current.active = true;
current.setValue('flow_context', contextId);
current.work_notes = 'Request restarted by ' + gs.getUserDisplayName();
current.update();
gs.info('RITM restarted: ' + current.number + ' with new Flow Context: ' + contextId);
//Redirect to the RITM record
action.setRedirectURL(current);
} catch (ex) {
gs.error('Error in restartFlow: ' + ex.message);
}
}
check client and use (checkOpen()) in Onclick & put (reopen_ritm) in Action name.
If it helps mark as helpfull.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 11:59 PM
So you wanted to share your code which will be helpful for other members?
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
03-19-2025 12:10 AM
@Ankur Bawiskar yes just wanted to share code so it will helpful someone.