In UI Macro infront of Location field need icon button once click it shows only related incident

Shekhar Deshin1
Mega Guru

@Ankur Bawiskar 

 

I need you help on In UI Macro in front of Location field need icon button once  I click it shows only related incident for that location which opened only in last 10 days.

So i used out of box UI Macro - user_show_incidents (which is same for caller).

On location table i can see icon and related incidents but how i can add the filter query for last 10days incident for same location.

where i can update in 'user_show_incidents' Ui Macro

 

Please suggest.

Thanks

Shekhar.

 

 

 

1 REPLY 1

Ankur Bawiskar
Tera Patron

@Shekhar Deshin1 

something like this

1) inside that UI macro get the inc sysId

2) then make GlideAjax call to script include and pass the location sysId

3) script include will query INC with this location, and then search for INCs with this location in last 10 days, for this you will have to use date time difference logic and then return array of sysIds

4) then update the query

<?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" icon="icon-tree-right"/>

<script>
// show related list
// todo: should be part of the PopupWindow class
// todo: needs new stack name
function showRelatedList(reference) {
    var s = reference.split('.');
    // Get the field name which is always last
    var referenceField = s[s.length - 1];
    var v = g_form.getValue(reference);

    // use GlideAjax here and send v so it sends location sysId to Ajax
    // arr holds array of incidents with this location in last 10 days

    var w = new GlideDialogWindow('show_list');
    w.setTitle('Related incidents');
    w.setPreference('table', 'incident_list');
    w.setPreference('sysparm_view', 'default');
    w.setPreference('sysparm_query', 'sys_idIN' + arr.toString());
    w.render();
}

</script>
</j:jelly>

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader