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

Deepak Kumar5
Kilo Sage

1) This is the sys_id of workflow which you can get from Workflow version table.


2) You have to run this code in Background Script (type in left nevigation and then paste code and run it)



Verify your workflow if you have many version to whick you have to revert then copy sys_id



find_real_file.png


find_real_file.png


Nice !   I wasn't aware of the right click, trick.... looks useful.  



FWIW - the Sys ID is the string output into the file name when you export the workflow.



Interestingly, in the "Show List" of the wf_workflow_version table the gear doesn't show the Sys ID.


I had to create a database view on the table to be able to add the Sys ID.


But I've got it.   Now just need to know where to run that code so I can disable the current workflow version.



Thank you for your insights.


Hi Deep K,



  Thank you for your response.


While I have administrator privileges on the platform, our platform is Geneva, and I am not seeing a "Scripts - Background" on my left side menu.   Does it go by another name?


Under System Definition I have these choices:


Script Includes


Fix Scripts


Client Scripts


Validation Scripts



I just want to make sure I run the code in the right place so I don't mess up the other 300 workflows already in the system.