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

Hitoshi Ozawa
Giga Sage
Giga Sage

 

Script Include

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

    myFunction: function() {
        var tableName = '<table name>';  // used sys_user during test
        var userName = this.getParameter('sysparm_user_name');

        var task = new GlideRecord(tableName);
        task.addQuery("requested_for.sys_id",userName);
        //task.addQuery("sys_id", userName);  // used during test
        task.query();
        if (task.next()) {
            var test = task.fieldName.getDisplayValue().toString();
            //var test = task.getDisplayValue().toString();  // used during test
            return test;
        }
        return '';
    },
    type: 'scriptIncludeName'
});

Client script

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:" + answer);
    g_form.setValue("variablebackendname", answer);  // variable name is usually all in lowercase

}

Output (using test)

find_real_file.png

find_real_file.png

Hi Hitoshi,

fieldName is of type "Date/Time".

I am getting that value as null.

What can be done to overcome this null issue?

Thanks,

Ram Prakash K R

I just changed my sample to return 'task.sys_created_on.getDisplayValue().toString();'

Script Include

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

    myFunction: function() {
        var tableName = '<table name>';
        var userName = this.getParameter('sysparm_user_name');

        var task = new GlideRecord(tableName);
        task.addQuery("requested_for.sys_id=",this.getParameter('sysparm_user_name'));
        //task.addQuery("sys_id", userName);
        task.query();
        if (task.next()) {
            var test = task.fieldName.getDisplayValue().toString();
            //var test = task.sys_created_on.getDisplayValue().toString();
            return test;
        }
        return '';
    },

    type: 'scriptIncludeName'
});

 

Also changed data type of variable "variablebackendname" to date/time.

Execution output

find_real_file.png

 

 

kutvaram
Tera Expert

Hi All,

Finally the below setting worked:

var test = task.getDisplayValue(fieldBackEndName);

Thanks all for your prompt replies.