why it is always returning "FALSE" value

chanikya
Tera Guru

Hi,

Can help me, what is wrong in script, it is always returning false. 

find_real_file.png

find_real_file.png

 

find_real_file.png

 

1 ACCEPTED SOLUTION

Joel Millwood2
Kilo Guru

Hi chanikya,

There looks to be a few errors in your code. I have redone both the Script Include and the Catalog Client Script below. Note these are just done by hand and have not been tested with a Catalog Item.

Script Include:

var ScheduleUtils = Class.create();
ScheduleUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	inUserSchedule: function() {
		var date = this.getParameter('sysparm_date');
		var startDate = new GlideDateTime(date);
		var inSchedule = false;
		var employee = this.getParameter('sysparm_emp');
		var user = new GlideRecord('sys_user');
		if(user.get(employee)) {
			var schedule = new GlideSchedule(user.getValue('schedule'));
			inSchedule = schedule.isInSchedule(startDate);
		}
		return inSchedule;
	},
	
	type: 'ScheduleUtils'
});

Catalog Client Script:

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	
	var date = g_form.getValue('date');
	var user = g_form.getValue('u_user');

	var scheduleUtils = new GlideAjax('global.ScheduleUtils');
	scheduleUtils.addParam('sysparm_name', 'inUserSchedule');
	scheduleUtils.addParam('sysparm_date', date);
	scheduleUtils.addParam('sysparm_emp', user);
	scheduleUtils.getXMLAnswer(function(answer) {
		if(answer == false) {
			g_form.clearValue('u_hours');
		} else {
			g_form.showErrorBox('date', 'Is in schedule');
			g_form.setValue('u_hours', 4);
		}
	});
	
}

Hopefully the above will be enough for you to resolve your issue! Can you also double check the names of the variables on your form? the u_ prefix normally exists on user created tables and fields however it is not automatically added on catalog variables.

View solution in original post

12 REPLIES 12

Chandra Prakash
Tera Expert

Hi Chanikya,

 It could be a reason that Script Include returns null value.

refer this thread 

https://community.servicenow.com/community?id=community_question&sys_id=df2f47e1dbdcdbc01dcaf3231f96...

 

Mark Correct if it helps.

Regards,

Chandra Prakash

Hi Chandra Prakash,

 

i didn't get you, i think we are using return this._isWithinSched(startDate, scheID);

so now how can we use this .

can you suggest me here please

Can i expect any updates please

Joel Millwood2
Kilo Guru

Hi chanikya,

There looks to be a few errors in your code. I have redone both the Script Include and the Catalog Client Script below. Note these are just done by hand and have not been tested with a Catalog Item.

Script Include:

var ScheduleUtils = Class.create();
ScheduleUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	inUserSchedule: function() {
		var date = this.getParameter('sysparm_date');
		var startDate = new GlideDateTime(date);
		var inSchedule = false;
		var employee = this.getParameter('sysparm_emp');
		var user = new GlideRecord('sys_user');
		if(user.get(employee)) {
			var schedule = new GlideSchedule(user.getValue('schedule'));
			inSchedule = schedule.isInSchedule(startDate);
		}
		return inSchedule;
	},
	
	type: 'ScheduleUtils'
});

Catalog Client Script:

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	
	var date = g_form.getValue('date');
	var user = g_form.getValue('u_user');

	var scheduleUtils = new GlideAjax('global.ScheduleUtils');
	scheduleUtils.addParam('sysparm_name', 'inUserSchedule');
	scheduleUtils.addParam('sysparm_date', date);
	scheduleUtils.addParam('sysparm_emp', user);
	scheduleUtils.getXMLAnswer(function(answer) {
		if(answer == false) {
			g_form.clearValue('u_hours');
		} else {
			g_form.showErrorBox('date', 'Is in schedule');
			g_form.setValue('u_hours', 4);
		}
	});
	
}

Hopefully the above will be enough for you to resolve your issue! Can you also double check the names of the variables on your form? the u_ prefix normally exists on user created tables and fields however it is not automatically added on catalog variables.