logo

NJP

CI UI Macro Actions for the Affected CIs List

Import · Jan 18, 2012 · article

Wednesday, 18 January, 2012 06:12 Written by Mark Stanger

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=truesys_id!=" + g_form.getUniqueValue() + "SUBQUERYsys_id,task,task_cici_item=" + gr.ci_item + "ENDSUBQUERYGROUPBYsys_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

View original source

https://web.archive.org/web/20121109062557/http://www.servicenowguru.com/system-ui/ui-actions-system-ui/show-bsm-ci-map-affected-cis-related-list/