restart flow designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2024 07:13 AM - edited ‎10-07-2024 07:16 AM
Hello Experts,
i have below scenario:
Create UI action to restart cancelled/rejected Requested Item
Name: Restart
Available when state = Closed Skipped or Closed Incomplete
Requires role Catalog Admin
If Parent REQ is closed, mark as active and set state to Pending Approval. Restart workflow
Set RITM state to 1 and active to true
Restart (Or re-run) flow associated with the RITM
Add work note: Request has been restarted by (current user display name)
i have written a script the script changes the states as per description and cancelling the approvals but not restarting the flow designer associated to RITM.
Please assist me.
//script to cancell the current flow designer and srart new flow
(function() {
var req = new GlideRecord('sc_request');
req.addQuery('sys_id', current.request);
req.query();
if (req.next()) {
if (req.request_state == 'closed_incomplete' || req.request_state == 'closed_skipped') {
req.setWorkflow(false);
req.active = true;
req.request_state = 'requested';
req.update();
// Restart workflow for REQ
new Workflow().restartWorkflow(req);
}
}
// Update approval records for RITM
var approvals = new GlideRecord('sysapproval_approver');
approvals.addEncodedQuery('sysapproval=' + current.sys_id.toString());
approvals.orderByDesc('sys_created_on');
approvals.query();
while (approvals.next()) {
approvals.state = 'cancelled';
approvals.update();
}
// Find and cancel related flow context records for 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');
}
// Restart the Flow Designer flow for RITM with new inputs
try {
var inputs = {
'request_item': current.sys_id.toString(),
'table_name': 'sc_req_item'
};
var contextId = grFlowContext.sys_id.toString();
var runner = sn_fd.FlowAPI.getRunner();
if (runner) {
// we also tried below API's but not working
runner.FlowAPI.startFlow('global. ', inputs);
//sn_fd.FlowAPI.executeFlow('global.hardware_requests', inputs);
} else {
gs.error('Flow Runner not found.');
}
// Optionally update the flow context record with new details
var updatedFlowContext = new GlideRecord('sys_flow_context');
if (updatedFlowContext.get(contextId)) {
updatedFlowContext.source_table = 'sc_req_item';
updatedFlowContext.source_record = current.sys_id.toString();
updatedFlowContext.update();
}
} catch (ex) {
gs.error('Error occurred: ' + ex.getMessage());
}
// Update the RITM record
current.active = true;
current.approval = 'not requested';
current.state = '1';
current.update();
// Add a work note to the RITM
current.work_notes = 'Request has been restarted by ' + gs.getUserDisplayName();
current.update();
// Redirect to the current RITM record
action.setRedirectURL(current);
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2024 10:51 AM
@shaik23 not sure if I understood your scenario properly but when you order one item it will never trigger flow for other item unless its order guide, where you will have multiple items(RITM's) generated under one request. It will be helpful if you share your cat item details and what exactly you are trying to achieve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2024 04:08 AM
when i ordered a item each catalog item has different flows so i am unable to give the flow name particularly,
as you said to give sn_fd.FlowAPI.executeFlow('flow_name', inputs); flow name inside flow api right the flow name is changing for each item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2024 04:18 AM
As you said we have to provide name on sn_fd.FlowAPI.executeFlow('flow_name', inputs);
when the names of the current ritm flow changes how we can give particular flow name, and when i requested a item in flow context table there are 3 entries below added screen shots