SATURDAY, OCTOBER 25, 2014

Edit a Workflow Directly from a Task

A

couple of weeks ago, I saw a great idea from Alex Yupanqui, who works for ServiceNow, to create UI actions to allow users to directly edit a graphical workflow from the associated record. I’ve taken this idea and cleaned things up a bit to make it usable and secure throughout the system.

You’re probably already familiar with the ‘Show Workflow’ and ‘Workflow Context’ UI action links that show up on task records when a workflow gets associated to it. These UI actions are extremely useful for identifying the state of the workflow as it relates to the task. As an administrator or consultant, you’re often trying to troubleshoot or fix an issue with the workflow, which requires the workflow editor. Unfortunately, this means you have to navigate to the module in the left nav and try to find the correct workflow to edit. The purpose of this solution is to cut out all of those extra steps to allow you to edit the workflow directly from the record it is bound to.

Edit Workflow

Here’s the UI action code. Notice that it’s set on the ‘Global’ table so that it will be available as a link on every form in the system. You’ll also notice that the ‘Condition’ field is set to allow access to only the ‘workflow_admin’ role, and to only display the link when a record has a workflow associated to it.

‘Edit Workflow’ UI Action
Name: Edit Workflow
Table: Global
Action name: show_workflow_editor
Order: 205
Form link: True
Client: True
Onclick: showWorkflowEditor()
Condition: gs.hasRole(‘workflow_admin’) && new Workflow().hasWorkflow(current)
Script:

function showWorkflowEditor(){
   //Open the workflow editor in a new window
   var wf = new GlideRecord('wf_context');
   wf.addQuery('id', g_form.getUniqueValue());
   wf.query();
   if(wf.next()){
      getTopWindow().popupOpenFocus('workflow_ide.do?sysparm_sys_id=' + wf.workflow_version, 'show_workflow_version', 950, 700, '', false, false);
   }
}

If you’ve set this global UI action up correctly, clicking the ‘Edit Workflow’ link will take you directly to the workflow editor for that specific workflow just as if you would have navigated through the module in the left nav.

Bonus UI Action

Here’s another UI action that you can use on the ‘wf_context’ table so that you have a quick link to edit the workflow when viewing a given workflow context. The basic ideas are the same, but the script and condition are a little bit different because we’re initiating the UI action from a specific table in this case.

‘Edit Workflow’ UI Action
Name: Edit Workflow
Table: Global
Action name: show_workflow_editor
Order: 105
Form link: True
Client: True
Onclick: showWorkflowEditor()
Condition: gs.hasRole(‘workflow_admin’)
Script:

function showWorkflowEditor(){
   //Open the workflow editor in a new window
   var id = g_form.getValue('workflow_version');
   getTopWindow().popupOpenFocus('workflow_ide.do?sysparm_sys_id=' + id, 'show_workflow_version', 950, 700, '', false, false);
}

2 Comments

Wendy Hoff 14-03-2012, 07:52

Hi, Do you know what I could have done wrong that I don’t see that at the bottom of my pages? I tried creating a new change also to see if it showed up but it didn’t. I don’t have the link at the bottom?? Thanks

Reply
Mark Stanger 14-03-2012, 08:19

You should make sure that the ‘Active’ checkbox is checked, that the ‘Form Link’ checkbox is checked, that the user you’re viewing with has the ‘workflow_admin’ role, and that you’ve actually got a workflow associated to your change. The link will only show under those conditions.

Reply

Leave a Reply


Latest Comments

  • Mark Stanger: Unless it is removable by using the methods described here, there’s no way I know of to remove it.
  • feroz shaik: Hi mark, I have used this link to remove fields but one [display = true] field remains there. Is it...
  • Senthil: Hi Valor, Please share the fix, i having the same issue which the event start time is request time date and...
  • Dave: Mark, works a treat. Thanks