restart flow designer

rognomolta
Tera Contributor

Hi all,

 i'm try to cancel the existing flow and try to retrigger a flow i write a UI action, currently i'm able to cancel the flow and restarting the flow again approvals getting triggered below script i have written  

UI action:

 

(function() {

    var req = new GlideRecord('sc_request');
    req.addQuery('sys_id', current.request);
    req.query();

    if (req.next()) {
            req.setWorkflow(false);
            req.active = true;
            req.request_state = 'requested';
            req.update();

            // Restart workflow for REQ (Traditional Workflow)
            new Workflow().restartWorkflow(req);
    
    }
    
    // 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(), null);
    }

   // Restart the Flow Designer flow for RITM
    try {
      // Restart the flow context for RITM
   sn_fd.FlowAPI.getRunner().restartFlowFromContext(grFlowContext.sys_id.toString(), null);

  } catch (ex) {
      gs.error('Error occurred: ' + ex.getMessage());
  }
    
    // Update the RITM record
    current.active = true;
   // current.state = '1'; // Set to active
    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);

})();

 

 

and i am sharing my requirement as well

Create UI action to restart cancelled/rejected Requested Item

Name: Restart

Available when state = Closed Skipped or Closed Incomplete

Requires role Catalog Admin

  1. If Parent REQ is closed, mark as active and set state to Pending Approval. Restart workflow

  2. Set RITM state to 1 and active to true

  3. Restart (Or re-run) flow associated with the RITM

  4. Add work note: Request has been restarted by (current user display name

    i'm sharing my screenshot:

    screenshot of flow context after rejecting the approval

    rognomolta_0-1728478391205.png

     

    After click on ui action a new approval is generated

    rognomolta_1-1728478700807.png

     

    screenshot of flow context after new approval is generated
    rognomolta_2-1728478887876.png

     


    screenshot of flow context after approves the approval
    rognomolta_3-1728479008630.png

    rognomolta_4-1728479037817.png

    rognomolta_5-1728479060711.png
    rognomolta_6-1728479082466.png

    rognomolta_7-1728479143273.png

    When approval is approver the flow is not running properly and skipping the to created a sc task and completed stages 
    please guide me
    Thank you,     

     

     

     

  

1 REPLY 1

Abbas_5
Tera Sage
Tera Sage

Hello @rognomolta,

For similar kind of issues, please refer to the links below:
https://www.servicenow.com/community/itsm-articles/restart-retrigger-a-flow-designer/ta-p/2306116

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0855865


If it is helpful, please mark it as helpful and accept the correct solution. In future, it might be helpful for someone to refer to this solution.

Thanks & Regards,

Abbas Shaik