How to call Script Include function from UI Macro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2019 06:12 AM
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
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):
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>
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2019 09:59 AM
Hi Milan,
there is similar question to which answer is provided; can you check that.
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader