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

Jaspal Singh
Mega Patron
Mega Patron

Hi Joseph,



You can try below snippet by creating a new UI Macro: show_related_requests




<?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_requests_${jvar_guid}:${ref}"/>


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


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


  title="${gs.getMessage('Show related requests')}" 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 = 'requested_for' + '=' + g_form.getValue(reference);


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


              var gdw = new GlideModal('show_list');


              gdw.setTitle(title);


              gdw.setSize(750);


              gdw.setPreference('table', 'sc_request_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>



Once done go to Requested For field on the Request form & do configure dictionary & add below attribute


find_real_file.png


Thank you this works., but now I have run into another issue. I want the incident and request Macro to be next to the callers name on the form, but I can only have one or the other. When I try to call both in the dictionary field it only displays the last macro called. Is there a way to display both on the same form? I am adding this to the call module as we need to know what the user has logged.


Hi Joseph,



Then you need make changes in UI Macros & then use both incident & requested item table in a single macro.


I am also trying to show both related incidents and requests using the same UI Macro, but can only get one or the other to display, and not both at the same time. How can I reference both tables in the same Macro and have them both display?