top of page

Exporting ServiceNow Workflows in One Click

  • Kiran Kumar
  • May 9, 2017
  • 2 min read

The components that make up a Graphical Workflow version are actually stored in 7 separate tables. It is possible to export a graphical workflow version but you have to do 7 separate exports to do it! In this post, I’ll show you how you can set up UI actions for some of these more complex export tasks.

Step 1 , Set up a Processor record to handle the export. No need to re-invent the wheel....ServiceNow has some built-in code to handle this and we just need to know how to leverage it.

ExportWorkflow - Processor

//Get the sys_id of the workflow version var sysID = g_request.getParameter('sysparm_sys_id'); //Get the sys_id of the workflow var wfID = g_request.getParameter('sysparm_wf_id'); var actID = '';//Query for workflow activities var act = new GlideRecord('wf_activity'); act.addQuery('workflow_version', sysID); act.query(); while(act.next()){ actID = actID + ',' + act.sys_id.toString(); }

//Export workflow version info to XML var exporter = new ExportWithRelatedLists('wf_workflow_version', sysID); exporter.addRelatedList('wf_stage', 'workflow_version'); exporter.addRelatedList('wf_activity', 'workflow_version'); exporter.addRelatedList('wf_condition', 'activity.workflow_version'); exporter.addRelatedList('wf_transition', 'to.workflow_version'); exporter.addRelatedList('wf_transition', 'from.workflow_version'); exporter.addRelatedList('wf_workflow_instance', 'workflow_version'); if(wfID != ''){ exporter.addQuerySet('wf_workflow', 'sys_id=' + wfID); } if(actID != ''){ exporter.addQuerySet('sys_variable_value', 'document_keyIN' + actID); } exporter.exportRecords(g_response);

Once you are ready with Processor , need to call it. It should be called by its path name 'export_workflow' followed by ‘.do’. It also needs to know what to export so you need to pass it the sys_id of the top-level record that you want to export…in this case, the sys_id of the ‘Workflow context’ record.

Export to XML - UI Action

Name: Export to XML Table: Workflow Version (wf_workflow_version) Order: 200 Form context menu: True Hint: Export workflow for importing in another instance Condition: gs.hasRole(“admin”) Script:

action.setRedirectURL('export_workflow.do?sysparm_sys_id=' + current.sys_id + '&sysparm_wf_id=' + current.workflow);



Once you’re done with this, you should have an ‘Export to XML’ UI action context menu item on your ‘Workflow version’ form



 
 
 

Comments


bottom of page