Show Related Incidents, Requests and Configuration Items

This helpful Macro builds off the Customer field on the incident table.

To get started, first create a UI Macro with the following attributes:

Name: show_more_user

Script:

<?xml version=”1.0″ encoding=”utf-8″ ?>

<j:jelly trim=”false” xmlns:j=”jelly:core” xmlns:g=”glide” xmlns:j2=”null” xmlns:g2=”null”>
<div class=”icon icon-add btn macro-icon”>
<!– <div class=”icon icon-view color-green macro-icon”> –>
<div class=”iframe-container”>
<g:macro_invoke macro=”user_show_incidents_incident_table” />
&#160;
<g:macro_invoke macro=”user_requested_items” />
&#160;
<g:macro_invoke macro=”user_show_assigned_ci” />
</div>
</div>
<style>
.macro-icon{
float:left;
}
.macro-icon:hover .iframe-container{
display:block;
}
.macro-icon:active .iframe-container{
display:block;
}
.iframe-container{
width:110px;
height:50px;
display:none;
position:absolute;
top:32px;
z-index:99999;
}
.iframe-container iframe{
width:400px;
height:300px;
border:none;
}
</style>
</j:jelly>

 

Add UI Macro:

Name: user_show_incidents

Script:

<?xml version=”1.0″ encoding=”utf-8″ ?>
<j:jelly trim=”false” xmlns:j=”jelly:core” xmlns:g=”glide” xmlns:j2=”null” xmlns:g2=”null”>
<g:evaluate var=”jvar_guid” expression=”gs.generateGUID(this);” />
<j:set var=”jvar_n” value=”show_incidents_${jvar_guid}:${ref}”/>
<a>
<span
id=”${jvar_n}”
onclick=”showRelatedList(‘${ref}’)”
name=”${jvar_n}”
aria-label=”${HTML:gs.getMessage(‘Show Related Incidents’)}”
title=”${gs.getMessage(‘Show Related Incidents’)}”
alt=”${gs.getMessage(‘Show Related Incidents’)}”
class=”icon ref-button icon-article-document btn btn-default”
></span>
</a>

<script>
// show related list
function showRelatedList(reference) {
try {
var displayValue = g_form.getDisplayBox(reference).value;
var title = ‘Showing records related to: ‘ + displayValue;
var s = reference.split(‘.’);
var referenceField = s[s.length – 1];
var query = referenceField + ‘=’ + g_form.getValue(reference);

var gdw = new GlideModal(‘show_list’);
gdw.setTitle(title);
gdw.setSize(750);
gdw.setPreference(‘table’, ‘incident_list’);
gdw.setPreference(‘sysparm_query’, query);
gdw.setPreference(‘title’, ‘A New Title’);
gdw.render();
} catch (e) {
jslog(‘error showing related list’);
jslog(e);
}
}

</script>
</j:jelly>

 

New UI Macro:

Name: user_show_assigned_ci

Script:

<?xml version=”1.0″ encoding=”utf-8″ ?>
<j:jelly trim=”false” xmlns:j=”jelly:core” xmlns:g=”glide” xmlns:j2=”null” xmlns:g2=”null”>
<g:evaluate var=”jvar_guid” expression=”Packages.com.glide.util.Guid.generate(this);” />
<j:set var=”jvar_n” value=”show_cis_${jvar_guid}:${ref}”/>
<a>
<span
id=”${jvar_n}”
onclick=”showRelatedCIList(‘${ref}’)”
name=”${jvar_n}”
aria-label=”${HTML:gs.getMessage(‘Show Related Configuration Items’)}”
title=”${gs.getMessage(‘Show Related Configuration Items’)}”
alt=”${gs.getMessage(‘Show Related Configuration Items’)}”
class=”icon ref-button icon-hardware btn btn-default”
></span>
</a>

<script>
// show related list
function showRelatedCIList(reference) {
var s = reference.split(‘.’);
var referenceField = s[1];
var v = g_form.getValue(referenceField);
var url = ‘cmdb_ci_computer_list.do?sysparm_target=incident.cmdb_ci&amp;amp;sysparm_query=u_login_name=’ + v;
url += ‘&amp;amp;sysparm_nameofstack=reflist&amp;amp;sysparm_clear_stack=true&amp;amp;sysparm_element=cmdb_ci&amp;amp;sysparm_reference=cmdb_ci&amp;amp;sysparm_view=sys_ref_list&amp;amp;sysparm_additional_qual=’;
popupOpenStandard(url, ‘related_list’, 950, 700, ”, false, false);
}
</script>
</j:jelly>

New UI Macro:

Name: user_requested_items

Script:

<?xml version=”1.0″ encoding=”utf-8″ ?>
<j:jelly trim=”false” xmlns:j=”jelly:core” xmlns:g=”glide” xmlns:j2=”null” xmlns:g2=”null”>
<g:evaluate var=”jvar_guid” expression=”gs.generateGUID(this);” />
<j:set var=”jvar_n” value=”show_ris_${jvar_guid}:${ref}”/>
<g:reference_decoration id=”${jvar_n}” field=”${ref}”
onclick=”showRelatedRIList(‘${ref}’); ”
title=”${gs.getMessage(‘Show requested items’)}” image=”images/flat_layout.gif”/>

<script>
// show related list
function showRelatedRIList(reference) {
var s = reference.split(‘.’);
var referenceField = s[1];
var v = g_form.getValue(referenceField);
var url = ‘sc_req_item_list.do?&amp;amp;sysparm_query=request.requested_for=’ + v;
var w = getTopWindow();
w.popupOpenFocus(url, ‘related_list’, 950, 700, ”, false, false);
}
</script>

</j:jelly>

 

 

okay! Now that we have that in the instance, the final step is to add the following to the dictionary attribute to the caller field on the incident form:

ref_contributions=show_more_user

 

If you have everything setup properly you should see a “+” symbol next to the customers name and when hovered over, gives you options for related incidents, requested items and associated computers!

 

Screen Shot 2016-08-30 at 5.41.30 PM