Script Include: Returning Null Value

kutvaram
Tera Expert

Hi All,

I have written an onLoad() Catalog Client Script where I used GlideAjax which is calling a script include.

Script Include has the simple glide record query where it fetches a date time field value based on the query result.

When I execute the script via background script, its returning the date time field value correctly.

But returning null value during onload() of the record producer.

What I am doing wrong in this?

Any help is much appreciated.

Thanks,

Ram Prakash K R

 

1 ACCEPTED SOLUTION

kutvaram
Tera Expert

Hi All,

Finally the below setting worked:

var test = task.getDisplayValue(fieldBackEndName);

Thanks all for your prompt replies.

View solution in original post

18 REPLIES 18

Hi,

Did you try to print what came in logs

var scriptIncludeName = Class.create();
scriptIncludeName.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

myFunction: function() {

var task = new GlideRecord("tableName");
task.addQuery("requested_for.sys_id",this.getParameter('sysparm_user_name'));
task.query();
if(task.next()) {
gs.info("Inside Script Include");
var test = task.fieldName.getDisplayValue();
return test;
}
},
type: 'scriptIncludeName'
});

what came in alert

function onLoad() {
//Type appropriate comment here, and begin script below

var userID = g_user.userID;
alert("Logged In User ID:" + userID);

var ga = new GlideAjax('scriptIncludeName');
ga.addParam('sysparm_name', 'myFunction');
ga.addParam('sysparm_user_name', userID);
ga.getXML(HelloWorldParse);

}

function HelloWorldParse(response) {
alert("Success");
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue("variableBackEndName", answer);
}

Regards
Ankur

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

Hi,

I am getting alerts pop up as:

 

1. Sys ID of the logged in user

2. Success

3. null

 

I am not getting value in logs.

 

 

Hi,

try to make this change

var scriptIncludeName = Class.create();
scriptIncludeName.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

myFunction: function() {

var task = new GlideRecord("tableName");
task.addQuery("requested_for.sys_id",this.getParameter('sysparm_user_name'));
task.query();
if(task.next()) {
gs.log("Inside Script Include");
var test = task.fieldName.getDisplayValue();
return test;
}
},
type: 'scriptIncludeName'
});

Regards
Ankur

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

Hi,

Not worked after making that change.

same as before.

Hi,

please compare with the script where it is working fine

Regards
Ankur

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