Restart workflow from UI action?

Edwin Fuller
Tera Guru

I have a UI action that reopens the record from a close state to an active state and sets the status back to in progress. I would also like to restart the workflow, can someone show me how that would be written?

Workflow Name = ConnectUs

Workflow sys_id = 17f8a0e46f452a00b2a0674f8e3ee4a7

UI Action Script

function worknotess(){

    if (g_form.getValue('work_notes') == '') {

          try {g_form.hideFieldMsg('work_notes');} catch(e) {}

          g_form.setMandatory('work_notes', true);

          g_form.showFieldMsg('work_notes','Work Notes are required');

    }

    gsftSubmit(null, g_form.getFormElement(), 'check_worknotes'); //MUST call the 'Action name' set in this UI Action

}

if (typeof window == 'undefined')

    serverResolve();

function serverResolve(){

    current.current_status = ('In Progress');

    current.actual_completion_date = '';

    current.update();

    }

1 ACCEPTED SOLUTION

Replace line new Workflow().restartWorkflow(current, true);


with new global.Workflow().restartWorkflow(current, true);


View solution in original post

8 REPLIES 8

You are very welcome Edwin. Thanks for participating in the community!


Good Morning, 

This doesn't seem to work on the London release, I have a UI Action on the sc_task table and want the Workflow to restart to adjust for the new Hardware Loan Date, I have most of it working except for the workflow restart:

I thought maybe as its in the sc_task table I would need to use a GlideRecord to go up a level to the req_item Table and restart the workflow from there...

Script:

var date = current.request_item.request.u_return_date;
var workflow_restarted = 'Yes';

var gdt = date.getGlideObject();
gdt.addDays(7);

var gr = new GlideRecord('sc_request');
gr.addQuery('sys_id', current.request_item.request);
gr.query();
if(gr.next()) {
gr.setValue('u_return_date', gdt);
gr.update();
}

var gr_sc_item = new GlideRecord('sc_req_item');
gr_sc_item.addQuery('sys_id', current.request_item);
gr_sc_item.query();
if(gr_sc_item.next()) {
new global.Workflow().restartWorkflow(current, true);
gs.log('Workflow restarted....');
}

Any suggestions I would be grateful for.

Kind Regards

Ashley

SanjivMeher
Kilo Patron
Kilo Patron

We use the following script to restart a workflow for a service request.



new WorkflowApprovalUtils().reset(current, "Restarting the workflow");


current.state = "requested";


current.u_last_approved_by = "None";


current.request_state = "requested";


current.update();



Please mark this response as correct or helpful if it assisted you with your question.

This is different from a service request and uses a custom workflow