
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 07:09 AM
Hello SN community,
My script include isn't working. I'm trying to display incidents based on a caller off a custom table that's been extended from the incident table. Here is the catalog client script and the script include. So, on the record producer there is a variable (caller_id, - this is a reference field off the user table). The second variable is Incident Number (u_incident_number - a reference field to the incident table). What I want to happen, is for the manager to enter in a Caller's name in the field, then for the scripts to return the most recent incident for that Caller. The form's purpose is for agent call evaluations....so the manager will be reviewing calls real-time and will fill out the form. Hopefully, I can script this so as the manager enters the Caller name, then the most current incident will auto-populate for the manager. Since the agent evaluations are real-time, the manager won't have time to query the incident table themselves.
Is this possible?
Catalog client script:
Type is On change
Variable is caller_id
------------------------------------------------------------------------------------
function onChange(control, oldValue, newValue, isLoading) {
if (oldValue == newValue) {
return;
}
{
var call = g_form.getValue('caller_id');
var ga = new GlideAjax('FindCallerINC');
ga.addParam('sysparm_name','FindCallerINC');
ga.addParam('sysparm_call', call);
ga.getXML(FindCallerINCParse);
}
function FindCallerINC(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_incident_number', 'answer');
}
}
Script include:
----------------------------------------------------------------------------------------
var FindCallerINC = Class.create();
FindCallerINC.prototype = Object.extendsObject(AbstractAjaxProcessor, {
FindCallerINC: function() {
var cl = this.getParameter("sysparm_call");
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', cl);
gr.addQuery('active','true');
gr.query();
while(gr.next()){
var number = gr.number;
var answer = number;
}
return answer;
}
});
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 10:07 AM
Hi Lola,
Could you please provide the screenshots of what you have configured. Please make sure that you are using the below script and in the advance reference qualifier it is being called as javascript:FindCallerINC();. My bad, I overlooked the way var cl is defined in my last response. Please do modify like below and give it a try.
function FindCallerINC() {
var cl = current.variables.caller_id;
var answer;
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', cl);
gr.addQuery('active','true');
gr.orderBy('sys_created'); //This is an optional one. You may remove this line
gr.query();
while(gr.next()) {
if (answer.length > 0) {
//build a comma separated string of groups if there is more than one
answer +=(',' + gr.sys_id).toString();
}
else {
answer = gr.sys_id.toString();
}
return 'sys_idIN' + answer;
}
}
}
I hope this helps.Please mark correct/helpful based on impact

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 10:53 AM
Hello Amlan,
It worked! Thanks for your assistance on this one! The only thing I needed to change was orderBy'sys_created' to orderByDesc'sys_created_on' and it sorted descending on the created field on the incident table which is what I was looking for!
Thanks again!!!