- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 11-13-2019 07:58 AM
At my current client in the aerospace industry, some custom work was built to integrate with an external purchasing system which requires initiating the order process via catalog item then waiting for some time and rechecking to see if the purchasing system has processed the request, pick up any errors generated and/or proceed with request closure.
In the case of certain errors, it was found there was a need to cancel the execution of workflow sitting in a 'waiting' state and restart.
To this end, the following script was written. The challenge here was that it had to run outside of a given record so we couldn't use the standard "current." to instance a glide record.
var current = 'POL0010239';
var gr = new GlideRecord ('proc_po_item');
gr.addQuery('number', current);
gr.query();
if(gr.next())
{
var oldWorkflow = new Workflow();
oldWorkflow.cancel(gr);
var newWorkflow = new Workflow();
newWorkflow.startFlow(new Workflow().getWorkflowFromName('Procurement Integration Workflow'), gr, '');
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
All you need to restart the workflow for a record is to do get the record that you want to restart the workflow for like you have then
new WorkflowApprovalUtils().cancelAll(gr, comment);
new Workflow().restartWorkflow(gr);
You can do that from any BR any script include triggered in any way you want.
So what is the issue you are having running your code?
Workflow API
//Your code in a diff way
var po = 'POL0010239';
var gr = new GlideRecord ('proc_po_item');
if(gr.get('number', po))
{
new Workflow().cancel(gr);
new Workflow().startFlow(new Workflow().getWorkflowFromName('Procurement Integration Workflow'), gr, '');
}
//Or if you really want to instantiate the workflow class
var wf = new Workflow();
wf.cancel(gr);
wf.startFlow(new Workflow().getWorkflowFromName('Procurement Integration Workflow'), gr, '');
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
We aren't having an issue with the code which is why I posted it as an article as opposed to a question.
I recognize that there are often 20 ways to get the job done in S/N. I didn't see anything in community which addressed this use case, similar but not the same, so posted it as an article for others to reference and gain what value they can from it.
Thanks for your additional input. I'm sure it will be valuable.