THURSDAY, JANUARY 19, 2017

CI UI Macro Actions for the Affected CIs List

T

he ability to associate Affected Configuration Items against a task is one of the most basic pieces of the various task forms in ServiceNow. ServiceNow gives you the ‘Configuration Item’ field to associate a single CI and the ‘Affected CIs’ related list in the event that your task needs to be associated to multiple CIs. I’ve written before about the benefits of tracking all of this information in one place to simplify reporting and usage requirements. During an onsite visit with a customer this week I noticed another opportunity to improve the functionality of the ‘Affected CIs’ related list. It would be very useful to be able to right-click items in the ‘Affected CIs’ related list and show a BSM Map or associated tasks just like you can do for the ‘Configuration Item’ field UI Macro icons. This post will show you how you can set these list context UI Actions up in your instances.

Configuration Item Reference Icons

Configuration Item Context Actions

Add a UI Action Context Menu to Show a BSM Map for a CI

This UI Action allows you to access (via a right-click context menu) a Business Service Map for any Configuration Item listed in the ‘Affected CIs’ related list.

Special thanks to Peter Oneppo for building the bulk of this script during a customer visit we had together this week!

‘Show CI map’ UI action
Name: Show CI map
Table: CI’s Affected (task_ci)
List context menu: True
Show insert: True
Show update: True
Client: True
Onclick: showBSMMapList()
Condition: gs.hasRole(‘itil’) && RP.isRelatedList()
Script:

function showBSMMapList() {
   //Retrieve the 'Affected CI' record
   var sysId = typeof rowSysId == 'undefined' ? gel('sys_uniqueValue').value : rowSysId;
   var gr = new GlideRecord('task_ci');
   gr.get(sysId);

   //Build the BSM map URL
   var attribs = 'table=cmdb_ci';
   attribs += ',id=' + gr.ci_item;
   attribs += ',level=4';
   attribs += ',ref=' + g_form.tableName + '.cmdb_ci';
   attribs += ',ciview=';
   attribs += ',restack=true';
   var url = new GlideURL('bsm_map2.do');
   url.addParam('sysparm_nameofstack', 'bsm');
   url.addParam('sysparm_attributes', attribs);

   //Open the BSM map URL in a new window
   var w = getTopWindow();
   w.popupOpenFocus(url.getURL(), 'show_bsm_map', 950, 700, '', false, false);
}

If you’ve set up the UI Action correctly, you should now be able to right-click a row in the ‘Affected CIs’ related list and display a BSM map by clicking the ‘Show CI Map’ option.

CI Context Action - CI BSM Map

Add a UI Action Context Menu to Show Related Tasks for a CI

Using a similar concept to that described above, you can create a context menu UI Action to display a dialog containing all associated, active tasks for any Configuration Item in the ‘Affected CIs’ related list.

‘Show Related Tasks’ UI action
Name: Show Related Tasks
Table: CI’s Affected (task_ci)
List context menu: True
Show insert: True
Show update: True
Client: True
Onclick: showTasksDialogList()
Condition: gs.hasRole(‘itil’) && RP.isRelatedList()
Script:

function showTasksDialogList() {
   //Retrieve the 'Affected CI' record
   var sysId = typeof rowSysId == 'undefined' ? gel('sys_uniqueValue').value : rowSysId;
   var gr = new GlideRecord('task_ci');
   gr.get(sysId);

   //Create and display the GlideDialogWindow
   var w = new GlideDialogWindow('show_list');
   w.setTitle('Other active tasks affecting this Configuration Item');
   w.setPreference('table', 'task_list');
   w.setPreference('sysparm_view', 'default');
   w.setPreference('sysparm_query', "active=true^sys_id!=" + g_form.getUniqueValue() + "^SUBQUERYsys_id,task,task_ci^ci_item=" + gr.ci_item + "^ENDSUBQUERY^GROUPBYsys_class_name");
   w.render();
}

If you’ve set up the UI Action correctly, you should now be able to right-click a row in the ‘Affected CIs’ related list and display a dialog showing open tasks for the CI by clicking the ‘Show Related Tasks’ option.

CI Context UI Action - Show Tasks

4 Comments

Erik 12-12-2013, 09:54

With the condition of: gs.hasRole(‘itil’) && RP.isRelatedList() I’m prompted with an error of “JavaScript parse error at line (1) column (12) problem = illegal character” Anyone have any ideas?

Reply
Mark Stanger 12-12-2013, 12:59

Probably a copy/paste issue with the quotes around ‘itil’. Remove the quotes and type them in manually and see if that helps.

Reply
Ravish Shetty 18-02-2014, 06:23

can we have a ui action in which we can have related items (ci_relations.xml) shown for a CI?

Reply
Mark Stanger 18-02-2014, 06:26

I don’t know of a direct way to do that, but you could accomplish the same thing by creating a custom view for CIs that includes nothing but the CI relations formatter, then popping that up in a new window from the UI action.

Reply

Leave a Reply


Latest Comments

  • David: It appears that I can hit sys_properties table with REST. This works, but I haven’t yet discovered the...
  • Mark Stanger: Hey David, It doesn’t surprise me that scoped apps have made this more difficult. I’m not...
  • David: Mark, do you have an example of how to do this in a scoped app? It seems there are many hoops to jump through...
  • Mark Stanger: The only possibility is to create a system property to override this in your application. Check out the...