
- 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 07:17 AM
this possible but your have to set the value equal to the sys id of the incident record in the incident reference field. so instead of returning gr.number return gr which should send back the sys_id.
also to get the most recent you need to add gr.orderBy(sys_created); to your query.
you also have your client script on change on the caller_id field. you can just use ga.addParam('sysparm_call', newValue);
also be sure to check client callable on your script include

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 09:05 AM
Hi Nathan,
Thanks for the reply. Yes, the client callable checkbox is enabled on the script include. I did adjust the script include as you mentioned so now it looks like this:
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.orderBy(sys_created);
gr.query();
while(gr.next()){
var number = gr;
var answer = number;
return answer;
}
}
});
The client script looks likes this:
Client Script:
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',newValue);
ga.getXML(FindCallerINCParse);
}
function FindCallerINC(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_incident_number', 'answer');
}
}
But, the record producer isn't returning the incident based on caller. It's only returning all incidents....any ideas? Thanks in advance!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 08:11 AM
Hi Lola,
There are couple of questions at first?
1. Is your variable 'Incident Number' (u_incident_number) is a 'Reference' type of variable which refers Incident Table?
- If Yes: You only can show a single record in that field. So in this case, can I assume that your requirement is to show all the records (which matches the condition) over there and gives the option to the user to choose anyone of the filtered records.
- If No: Can I assume that the variable type is 'Single Line Text/Multi Line Text'? And do you want to show all the Incident numbers (comma separated) in that variable?
If your Requirement is the First One (Variable is of Reference type) then the Script Include would look like below:
var FindCallerINC = Class.create();
FindCallerINC.prototype = Object.extendsObject(AbstractAjaxProcessor, {
FindCallerINC: function() {
var cl = this.getParameter("sysparm_call");
var answer;
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', cl);
gr.addQuery('active','true');
gr.orderBy('sys_created');
gr.query();
while(gr.next()){
answer+ = (',' + gr.sys_id).toString();
}
else{
answer= gr.sys_id.toString();
}
return 'sys_idIN' + answer;
}
}
If your Requirement is the Second One (Variable is of Single Line Text/Multi Line Text type) then the Script Include would look like below:
var FindCallerINC = Class.create();
FindCallerINC.prototype = Object.extendsObject(AbstractAjaxProcessor, {
FindCallerINC: function() {
var cl = this.getParameter("sysparm_call");
var answer;
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', cl);
gr.addQuery('active','true');
gr.orderBy('sys_created');
gr.query();
while(gr.next()){
answer+ = (',' + gr.number).toString();
}
else{
answer= gr.number.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 08:30 AM
Hi Amlan,
Thanks for the reply! I used your script, labeled "First One" but it's still not returning results as expected. Yes, u_incident_number is a reference field to the incident table. The only change I made to the script was the 'while' statement. I had to change it to 'if'.
var FindCallerINC = Class.create();
FindCallerINC.prototype = Object.extendsObject(AbstractAjaxProcessor, {
FindCallerINC: function() {
var cl = this.getParameter("sysparm_call");
var answer;
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', cl);
gr.addQuery('active','true');
gr.orderBy('sys_created');
gr.query();
if(gr.next()){
answer+ = (',' + gr.sys_id).toString();
}
else{
answer= gr.sys_id.toString();
}
return 'sys_idIN' + answer;
}
}