Is there a way to update workflow context which is already attached in change

Hitesh targe
Tera Expert

Hi All,

is there a way to update workflow context which is attached in change request.

There is a change request which is already opend and we have modified the normal change request workflow. is there a way to update already attached workflow with new chages(approval matrix)

Please suggest

Thanks

3 REPLIES 3

marcguy
ServiceNow Employee
ServiceNow Employee

I think you may need to use a script and call these utilities to either cancel or delete the existing workflow context and then restart a fresh workflow using the updated version:


Workflow Script - ServiceNow Wiki


dunstanchristop
Tera Contributor

Workflow context is a running instance of the workflow, I have not been able to replace an existing context that ran/waiting to run/running currently.


But you can cancel the existing context and start a new workflow context.



Did you get the answer for this? I resolved this issue by canceling the workflow context running and starting a new workflow.


You want to identify the context by querying the wf_context table and identify the specific workflow context that's related to your task/extended/custom table record.


Use the workflow script include library


to cancel the workflow by


Cancel the specific running workflow context and all subflows This is the normal, acceptable way to cancel a workflow that is in a wait state.


                        * @param context


                        * GlideRecord on table wf_context of the context to cancel


context - glide record for workflow context that you want to cancel



var oWorkflow = new global.Workflow;


oWorkflow.cancelContext(context);


oWorkflow.broadcastKill(context);



* Broadcast the Kill command to all nodes on an instance. Use this to Kill a workflow that is not responding. This will not


                        * affect a workflow that is in a wait state. Use cancel(...) to stop a workflow in a wait state.


                        * @param context


                        *   GlideRecord on table wf_context of the context to kill



Now that you canceled the workflow context start the workflow


var newcontext = oWorkflow.startFlow(<workflowId:string>, <Glide Record of the task e.g. _change>, _change.operation(),{});



We are all borgs with the collective conscience knowledge of those came before us and passed on to us. Sharing is caring so share!


Konstantin7
Mega Guru

I have not tested but you could look into 

restartWorkflow(GlideRecord current, Boolean maintainStateFlag)

 

More info: Workflow api: https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=c_WorkflowAPI