How to call Script Include function from UI Macro

Milan13
Giga Expert

Hello,

please see below print screen - I need to press the button next to custom Location field in order to get all incidents to related to chosen location.

I tried to get this output using calling GlideAjax from UI action calling Script Include function.

What I need is to call this Script Include Function in my UI macro and have no idea how...

Please see code snippets below and advise if you can, your help will be much appreciated.

Thanks a lot!

Milan

find_real_file.png

Script Include function (just the function snippet - the name of the script include is "IncidentUtils1"):

getLocationUsers: function () {
//variable for Incident custom field u_location
//returns array of user sys IDs from sys_user table based on u_location field in incident form
var customIncLocUsers = [];
//returns incidents - those with caller_id - caller_id supplied with array of user sys IDs from array customIncLocUsers
var customIncLocIncs = [];


var cust_inc_locSi = this.getParameter('sysparm_cust_inc_loc');

var userGR = new GlideRecord('sys_user');
userGR.addQuery('location', cust_inc_locSi);
userGR.query();
while (userGR.next()) {
customIncLocUsers.push(userGR.getValue('sys_id').toString());
}


JSON.stringify(customIncLocUsers);


var incidentGR = new GlideRecord('incident');

incidentGR.addQuery('caller_id', 'IN', customIncLocUsers);
incidentGR.addQuery('state','NOT IN', '7,8');
incidentGR.query();
while (incidentGR.next()) {
customIncLocIncs.push(incidentGR.getValue('number'));
}

return JSON.stringify(customIncLocIncs);

},

This is how I call it from UI Action by pressing a button on incident form (this works):

var ga = new GlideAjax('IncidentUtils1');
ga.addParam('sysparm_name', 'getLocationUsers');
ga.addParam('sysparm_cust_inc_loc', g_form.getValue('u_location'));
ga.getXML(AjaxParse);


function AjaxParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}

This is what I get as aresult when applying the UI action (array of incident numbers):
find_real_file.png

And this is where I need to pass the GlideAjax call calling the Script Include function...this apparently does not work...

<?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_guid3" expression="gs.generateGUID(this);" />
<j:set var="jvar_n3" value="show_incidents_${jvar_guid3}:${ref}"/>
<g:reference_decoration id="${jvar_n3}" field="${ref}"
onclick="showLocationIncidents('${ref}'); "
title="${gs.getMessage('Show Incident for given Location')}" image="images/icons/tasks.gifx" icon="icon-tree-right"/>


<script>

var ga = new GlideAjax('IncidentUtils1');
ga.addParam('sysparm_name', 'getLocationUsers');
ga.addParam('sysparm_cust_inc_loc', g_form.getValue('u_location'));
ga.getXML(AjaxParse);



function AjaxParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");

function showLocationIncidents(reference) {

var w = new GlideDialogWindow('show_list');
w.setTitle('Location incidents');
w.setPreference('table', 'incident_list');
w.setPreference('sysparm_view', 'default');
w.setPreference('sysparm_query', 'numberIN' + answer);
w.render();
}


}

</script>


</j:jelly>

 

 

 

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Milan,

there is similar question to which answer is provided; can you check that.

https://community.servicenow.com/community?id=community_question&sys_id=20448b29dbd8dbc01dcaf3231f96...

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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