Script include and client script not returning any values

Shalika
Tera Expert

I have a catalog item with variable "Change Request" which is a refrence field to change request table and another variable "SP Email" .I have to fetch the email ID of SP change coordinator from change request table .

I am using script include and onChange client script for this but not able to fetch any values. 

Shalika_0-1668056336430.png

onChange Client Script

 

Shalika_1-1668056382844.png

 

 

1 ACCEPTED SOLUTION

Sagar Pagar
Tera Patron

Hi @Shalika,

 

I agree with @Tony Chatfield1, In your script include, line

var ciID = this.getParameter('sysparm_name');


should be

var ciID = this.getParameter('sysparm_ci');

 

Note - 

It should be same parameter name used in client scritps Glide ajax call.

ga.addParam('sysparm_ci', g_form.getValue('change_request_id'));

 

 

Thanks,

Sagar Pagar 

The world works with ServiceNow

View solution in original post

5 REPLIES 5

Tony Chatfield1
Kilo Patron

Hi, what are the results of your debugging?

Is the serverside function called and are you passing in the correct parameters?

Is the correct value returned to the client script?
screenshots are not an appropriate method to share code, and you should use plain text.

But looking at you images I don't think you are referencing the correct parameter inside getEmail() - IE you are referencing sysparm_name and I think you might want  sysparm_ci

Client Script -

function onChange(control, oldValue, newValue, isLoading) {

if (newValue == '') {
g_form.setValue('sp_change_coordinator_email', '');
}

var ga = new GlideAjax('emailSp');

ga.addParam('sysparm_name', 'getEmail');
ga.addParam('sysparm_ci', g_form.getValue('change_request_id'));
ga.getXML(doPopulate);
}

function doPopulate(response) {

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

g_form.setValue('sp_change_coordinator_email', answer);

}

 

Script Include -

var emailSp = Class.create();
emailSp.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getEmail: function() {

var retVal = '';
var ciID = this.getParameter('sysparm_name');
var ci = new GlideRecord('change_request');
// If Business Service found, return its product code
if (ci.get(ciID)) {
if (ci.assigned_to != '') {
retVal = ci.assigned_to.email;
}
}
return retVal;
}


});

What should I use instead of sysparm_ci?

RaghavSh
Kilo Patron

Line no. 6 in your script include is not correct, it should be:

var ciID = this.getParameter('sysparm_ci') instead of 'sysparm_name' because you are passing sys_id of change request in 'sysparm_ci' from your client script.


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023

Jack
Tera Guru

hi Shalika,

your script include - code line 6 is wrong parm name

Capture.JPG

hope this help!