UI Macro to show Active Incidents and requests

josephd01
Mega Guru

Hi,

I would like to create a UI Macro that will display active incidents and requests for the caller. I was able to find the below on the ServiceNow website, but this only displays the Active Incidents for the user.

<?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}"/>  

<g:reference_decoration id="${jvar_n}" field="${ref}"  

  onclick="showRelatedList('${ref}'); "  

  title="${gs.getMessage('Show related incidents')}" image="images/icons/tasks.gifx"/>  

 

<script>  

// show related list  

function showRelatedList(reference) {  

      try {  

              var displayValue = g_form.getDisplayBox(reference).value;  

              var title = 'Showing records related to: ' + displayValue;  

              var query = 'caller_id' + '=' + g_form.getValue(reference);  

              query += '^' + 'active=true';  

 

              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>    

Thanking you in advance

1 ACCEPTED SOLUTION

ayman_h
Kilo Sage
Kilo Sage

To display both ACTIVE Incidents and Requests for a user on a popup, use this code below

 

<?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_calls_${jvar_guid}:${ref}"/>
<g:reference_decoration id="${jvar_n}" field="${ref}"
onclick="showRelatedList('${ref}'); "
title="${gs.getMessage('Show related calls')}" image="images/icons/tasks.gifx" icon="icon-tree-right"/>

<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);

//get user sys_id
var v = g_form.getValue(referenceField);

var gdw = new GlideModal('show_list');
gdw.setTitle(title);
gdw.setSize(750);
gdw.setPreference('focusTrap', true);
gdw.setPreference('table', 'task_list');
gdw.setPreference('sysparm_query','active=true^ref_incident.caller_id=' + v + '^ORref_sc_request.requested_for=' + v);
gdw.setPreference('title', 'A New Title');
gdw.render();
} catch (e) {
jslog('error showing related list');
jslog(e);
}
}

</script>
</j:jelly>

View solution in original post

7 REPLIES 7

I'm also trying to show both requests and incidents for callers using the same UI Macro, but I cannot get them both to display, only one or the other. I can't figure out how to adjust the script to reference both tables in the same Macro. I'm currently using the following to display incidents; how can I fix this to show both?

function showRelatedLists(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];
		if (referenceField == 'caller') {
			referenceField = 'caller_id';
		}
		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);
	}
}

ayman_h
Kilo Sage
Kilo Sage

To display both ACTIVE Incidents and Requests for a user on a popup, use this code below

 

<?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_calls_${jvar_guid}:${ref}"/>
<g:reference_decoration id="${jvar_n}" field="${ref}"
onclick="showRelatedList('${ref}'); "
title="${gs.getMessage('Show related calls')}" image="images/icons/tasks.gifx" icon="icon-tree-right"/>

<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);

//get user sys_id
var v = g_form.getValue(referenceField);

var gdw = new GlideModal('show_list');
gdw.setTitle(title);
gdw.setSize(750);
gdw.setPreference('focusTrap', true);
gdw.setPreference('table', 'task_list');
gdw.setPreference('sysparm_query','active=true^ref_incident.caller_id=' + v + '^ORref_sc_request.requested_for=' + v);
gdw.setPreference('title', 'A New Title');
gdw.render();
} catch (e) {
jslog('error showing related list');
jslog(e);
}
}

</script>
</j:jelly>

Ganesh90
Tera Expert

in san diego they add a new function function decorationshow.

(function() {
function decorationShow(element, original, changed, loading) {
var $refButton = $j(gel('${jvar_n}'));
$refButton.attr('role', 'button');
}
var n = '${jvar_n}'.replace(/./g, '');
var h = new GlideEventHandler('onLoad' + n, decorationShow, '${ref}');
g_event_handlers.push(h);
})();

 

what this function is doing?