How to Revert a Workflow to prior version

servicetrout
Tera Expert

I see from this link, https://community.servicenow.com/thread/236445?q=How%20to%20revert%20workflow

that one can revert to a prior workflow with this code:

For deactivating the current.

var getInc = new GlideRecord('wf_workflow_version');

if(getInc.get('3b95753ad0d60200085a28e2b5794e1e')) //change

{

getInc.published=false;

getInc.update();

}

To publish old one

var getInc = new GlideRecord('wf_workflow_version');

if(getInc.get('3b95753ad0d60200085a28e2b5794e1e')) //change

{

getInc.published=true;

getInc.update();

}

I understand one can not revert through the UI interface that this needs to be done pro-grammatically, but, couple of questions.

1) From the example above, I am guessing '3b95753ad0d60200085a28e2b5794e1e' is the reference to a specific workflow version.

Is that the same string I see in the name when I export the workflow to a .XML file?

2)   Where exactly do I go to run that code?   Would I run that as a new Fix Script?

Would this work ?

  a) Export a working workflow.

  b) Delete the problematic workflow (Ah, scratch this, I see it will not let me delete the current workflow).

  c)   Import the working workflow version

Thank you in advance.

1 ACCEPTED SOLUTION

Yes, it is "Scripts - Background" from left navigation.


View solution in original post

9 REPLIES 9

Yes, it is "Scripts - Background" from left navigation.


Hello Deepak



Can this be captured in a update set?


No you can't. Admin have to run Background script manually on all instances.



You can use Fix script and capture it in updateset.


Not sure why this didn't come up in my initial search but this was helpful:


Background Scripts — ServiceNow Elite



After setting account to security_admin, was able to see the Scripts - Background.


After substituting in the relevant workflow Sys IDs, in the code snippet above:


  A) Tested just setting the current workflow to unpublished, first.   Worked fine.


B) Ran the second code snippet and everything worked fine.


Manirul1
Tera Contributor

The easiest way is 

  1. Go to the workflow record in the wf_workflow table
  2. Right click in the form header, go to 'Show File Properties'
  3. Add the 'versions' related list to the form if it's not already there
  4. Right click the version you want to revert to, click 'Revert to this Version'
  5. Click 'Ok' on the dialog, and the workflow is reverted

Thanks

Manirul