Script include returning NULL to Client script

Omkar Jori
Tera Expert

Hello,

I have created a script include to check if the date entered is in scheule or not, but the script include is returning value as Null.

Please check the below script

Script include:

var execution_date_check = Class.create();
execution_date_check.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    isPublic: function() {
        return true;
    },
    scheduleCheck: function() {
		
        var execution_date = this.getParameter('execution_date');
        execution_date = new GlideDateTime(this.execution_date.getDisplayValue());

		var flag;

        var scheduleID_holidays = new GlideSchedule("755bc0091ba908107a44fd14cc4bcb0d");
		if(scheduleID_holidays.isInSchedule(execution_date)) {
			flag = true;
		}
		else {
			flag = false;
		}
        
        return flag;

    },
    type: 'execution_date_check'
});

 

Client Script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var execution_date = g_form.getValue("u_execution_date_and_time");
    var dateTime = execution_date.split(' ');
    var date = dateTime[0];

	var answer = "";

    var ga = new GlideAjax('sn_customerservice.execution_date_check'); //Scriptinclude
    ga.addParam('sysparm_name', 'scheduleCheck'); //Method
    ga.addParam('execution_date', date); //Parameters
    ga.getXML(HelloWorld);

    function HelloWorld(response) {
        answer = response.responseXML.documentElement.getAttribute('answer');
	alert(" answer : " + answer);
    }
}

 

Both the client script and script include are in Customer service scope and Client callable is enabled in Script include.

1 ACCEPTED SOLUTION

Omkar Jori
Tera Expert

I got the solution, as I removed the .getDisplayValue() and it worked.

execution_date = new GlideDateTime(execution_date.getDisplayValue());

 After change

execution_date = new GlideDateTime(execution_date);​

 

 

View solution in original post

5 REPLIES 5

Nick Parsons
Mega Sage

Have you checked your system logs for any errors within your client script, for example, you're using this.execution_date which isn't a property of your script include and may be causing your script to fail:

 

execution_date = new GlideDateTime(execution_date.getDisplayValue()); // removed: `this.`

 

 

Hi @Nick Parsons ,
Thank you for your reply.
I tried removing this but getting the same Null in the alert.
Nothing is generating in system logs.

Sandeep Rajput
Tera Patron
Tera Patron

@Omkar Jori Could you please update your client script and script include as follows and see if it works.

 

var execution_date_check = Class.create();
execution_date_check.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    isPublic: function() {
        return true;
    },
    scheduleCheck: function() {
		
        var execution_date = this.getParameter('sysparm_execution_date');
        execution_date = new GlideDateTime(this.execution_date.getDisplayValue());

		var flag;

        var scheduleID_holidays = new GlideSchedule("755bc0091ba908107a44fd14cc4bcb0d");
		if(scheduleID_holidays.isInSchedule(execution_date)) {
			flag = true;
		}
		else {
			flag = false;
		}
        
        return flag;

    },
    type: 'execution_date_check'
});

 

Client script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var execution_date = g_form.getValue("u_execution_date_and_time");
    var dateTime = execution_date.split(' ');
    var date = dateTime[0];

	var answer = "";

    var ga = new GlideAjax('sn_customerservice.execution_date_check'); //Scriptinclude
    ga.addParam('sysparm_name', 'scheduleCheck'); //Method
    ga.addParam('sysparm_execution_date', date); //Parameters
    ga.getXML(HelloWorld);

    function HelloWorld(response) {
        answer = response.responseXML.documentElement.getAttribute('answer');
	alert(" answer : " + answer);
    }
}

 

Root cause: You forgot to add sysparm_ suffix before execution_date parameter in client script and script include.

Omkar Jori
Tera Expert

Hi @Sandeep Rajput ,
I did tried adding the sysparm, but no luck.
I understood that there is issue with the date format which I am passing and checking in the script include.
Please help if you notice anything