We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

HELP!!! 'Date must be within the standard change window' error

abigailtaba
Tera Expert
var CNAChangeHelperAJAX = Class.create();
CNAChangeHelperAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	hasOpenTask: function() {
		var changeSysID = this.getParameter('sysparm_change_sys_id');
		var task = new GlideRecord('change_task');
		task.addActiveQuery();
		task.addQuery('change_request',changeSysID);
		task.setLimit(1);
		task.query();
		return task.hasNext();
	},
	
	isWithinStandardWindow: function() {
		var crSysID = this.getParameter('sysparm_cr_sys_id');
		gs.log("Value crSysID: " + crSysID);
		var compareDate = this.getParameter('sysparm_date');
		gs.log("Value: " + compareDate);
		var format = this.getParameter('sysparm_date_format');
		var changeRequest = new GlideRecord('change_request');
		if(changeRequest.get(crSysID)) {
			var producer = changeRequest.std_change_producer_version;
			if(!producer.nil()) {
				var proposal = producer.std_change_proposal;
				var schedule;
				var date = new GlideDateTime();
				date.setDisplayValue(compareDate,format);
				
				
				// date.add(-date.getTZOffset());				
				
				schedule = new GlideSchedule(proposal.u_schedule.sys_id);
				var returnValue = schedule.isInSchedule(date/*,gs.getSession().getTimeZoneName()*/);
				return returnValue;
			}
		}
		return false;
	},
	
	type: 'CNAChangeHelperAJAX'
});

I keep receiving this error "Date must be within the standard change window", and I see the error came from this client script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	
	if(g_form.getValue('type') == 'standard') {
		g_form.hideFieldMsg('start_date',true);
		var ga = new GlideAjax('CNAChangeHelperAJAX');
		ga.addParam('sysparm_name','isWithinStandardWindow');
		ga.addParam('sysparm_cr_sys_id',g_form.getUniqueValue());
		ga.addParam('sysparm_date_format',g_user_date_time_format);
		ga.addParam('sysparm_date',newValue);
		ga.getXML(StartDateParse);
	}
	
	function StartDateParse(response) {
		var answer = response.responseXML.documentElement.getAttribute("answer");
		if(answer != 'true') {
			g_form.clearValue('start_date');
			g_form.showFieldMsg('start_date','Date must be within the standard change window','error');
		}
	}}

 I tried with different hours but I keep receiving the same error, and I'm not able to see why this happening in there any error on the code?
I'm trying to schedule a time with a standard change request

4 REPLIES 4

Anand Kumar P
Tera Patron

Hi @abigailtaba ,

Check proposal is not empty

isWithinStandardWindow: function() {
    var crSysID = this.getParameter('sysparm_cr_sys_id');
    gs.log("Value crSysID: " + crSysID);
    var compareDate = this.getParameter('sysparm_date');
    gs.log("Value: " + compareDate);
    var format = this.getParameter('sysparm_date_format');
    var changeRequest = new GlideRecord('change_request');
    
    if (changeRequest.get(crSysID)) {
        var producer = changeRequest.std_change_producer_version;
        
        if (!producer.nil()) {
            var proposal = producer.std_change_proposal;
          
            if (proposal) {
                var schedule = new GlideSchedule(proposal.u_schedule.sys_id);
                var date = new GlideDateTime();
                date.setDisplayValue(compareDate, format);
                // date.add(-date.getTZOffset());
                var returnValue = schedule.isInSchedule(date);
                return returnValue;
            }
        }
    }
    
    gs.log("Failed to determine if date is within the standard change window.");
    return false;
},

Please mark it as solution proposed and helpful if it serves your purpose.

Thanks,

Anand

How i can check the proposal time?

@abigailtaba ,

Try above script i am saying proposal not empty in if condition.

if (proposal) {
                var schedule = new GlideSchedule(proposal.u_schedule.sys_id);

Thanks,

Anand

 

Hello @Anand Kumar P 

Abigail_0-1698927545214.png

I still received the same error

And this does not happen with all standard changes only with a few