How to display warning message for users

Nag9
Tera Expert

Hello Experts, i have below requirement

 

How to display error message to user when he modfies the start date inside freezing period, here is the exact info

1. After the change is Approved, the freeze dates in the calender should be disabled only for the user to select and the alert message should be dispalyed stating that 'The Freeze dates are disabled for selection after the change is Approved. Reach out to Change_Managers for assisitance'.
2. The Change Managers would be able to modify it to freeze dates.
3. The users should still be able to modify it to other non-freeze dates once the change is Approved.

 

 

How can we achieve this

1 ACCEPTED SOLUTION

Hello Nag,

In general, it is better to store the freeze dates in the database or use one of the existing SN feature something like blackout schedules and create a schedule with your freeze dates and compare your dates with this.

For now, you can use this below code as a quick fix.

Script Include

var Check_freeze_dates = Class.create();
Check_freeze_dates.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	check_freeze_dates:function() {
		var date_to_check = this.getParameter('sysparm_date');
		var gdt = new GlideDateTime(date_to_check);
		freeze_date_start1=new GlideDateTime("2019-08-31 00:00:00");
		freeze_date_end1=new GlideDateTime("2019-09-02 23:59:59");
		freeze_date_start2=new GlideDateTime("2019-11-25 00:00:00");
		freeze_date_end2=new GlideDateTime("2019-12-04 23:59:59");
		freeze_date_start3=new GlideDateTime("2019-12-15 00:00:00");
		freeze_date_end3=new GlideDateTime("2020-01-01 23:59:59");
		
		if((gdt.after(freeze_date_start1)&&gdt.before(freeze_date_end1)) || (gdt.after(freeze_date_start2)&&gdt.before(freeze_date_end2)) || (gdt.after(freeze_date_start3)&&gdt.before(freeze_date_end3))) {
			gs.log("Within the freezed date schedule "+date_to_check);
			return 1;
		} else {
			gs.log("NOT in the freezed date schedule "+date_to_check);
			return 0;
		}
	},
	type: 'Check_freeze_dates'
});

 

Client Script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	//Call SI to check whether the date is in the freezed dates period
	if(g_form.getValue("state") == 1) {
		var ga = new GlideAjax('Check_freeze_dates');
		ga.addParam('sysparm_name','check_freeze_dates');
		ga.addParam('sysparm_date',newValue);
		ga.getXML(callback);
		function callback(response)
		{
			var answer = response.responseXML.documentElement.getAttribute("answer");
			if(answer==1) {
				g_form.addInfoMessage("Please select the date which is NOT in the freeze dates section");
				g_form.setValue("start_date","");
			}
		}
	}
}

View solution in original post

6 REPLIES 6

Hello Nag,

In general, it is better to store the freeze dates in the database or use one of the existing SN feature something like blackout schedules and create a schedule with your freeze dates and compare your dates with this.

For now, you can use this below code as a quick fix.

Script Include

var Check_freeze_dates = Class.create();
Check_freeze_dates.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	check_freeze_dates:function() {
		var date_to_check = this.getParameter('sysparm_date');
		var gdt = new GlideDateTime(date_to_check);
		freeze_date_start1=new GlideDateTime("2019-08-31 00:00:00");
		freeze_date_end1=new GlideDateTime("2019-09-02 23:59:59");
		freeze_date_start2=new GlideDateTime("2019-11-25 00:00:00");
		freeze_date_end2=new GlideDateTime("2019-12-04 23:59:59");
		freeze_date_start3=new GlideDateTime("2019-12-15 00:00:00");
		freeze_date_end3=new GlideDateTime("2020-01-01 23:59:59");
		
		if((gdt.after(freeze_date_start1)&&gdt.before(freeze_date_end1)) || (gdt.after(freeze_date_start2)&&gdt.before(freeze_date_end2)) || (gdt.after(freeze_date_start3)&&gdt.before(freeze_date_end3))) {
			gs.log("Within the freezed date schedule "+date_to_check);
			return 1;
		} else {
			gs.log("NOT in the freezed date schedule "+date_to_check);
			return 0;
		}
	},
	type: 'Check_freeze_dates'
});

 

Client Script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	//Call SI to check whether the date is in the freezed dates period
	if(g_form.getValue("state") == 1) {
		var ga = new GlideAjax('Check_freeze_dates');
		ga.addParam('sysparm_name','check_freeze_dates');
		ga.addParam('sysparm_date',newValue);
		ga.getXML(callback);
		function callback(response)
		{
			var answer = response.responseXML.documentElement.getAttribute("answer");
			if(answer==1) {
				g_form.addInfoMessage("Please select the date which is NOT in the freeze dates section");
				g_form.setValue("start_date","");
			}
		}
	}
}

Here is the updated SI with change manager condition. Check and change the group as per your instance.

var Check_freeze_dates = Class.create();
Check_freeze_dates.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	check_freeze_dates:function() {
		var date_to_check = this.getParameter('sysparm_date');
		var gdt = new GlideDateTime(date_to_check);
		freeze_date_start1=new GlideDateTime("2019-08-31 00:00:00");
		freeze_date_end1=new GlideDateTime("2019-09-02 23:59:59");
		freeze_date_start2=new GlideDateTime("2019-11-25 00:00:00");
		freeze_date_end2=new GlideDateTime("2019-12-04 23:59:59");
		freeze_date_start3=new GlideDateTime("2019-12-15 00:00:00");
		freeze_date_end3=new GlideDateTime("2020-01-01 23:59:59");
		var currentUser = gs.getUser();
		if(!currentUser.isMemberOf('Change Management')) {
			if((gdt.after(freeze_date_start1)&&gdt.before(freeze_date_end1)) || (gdt.after(freeze_date_start2)&&gdt.before(freeze_date_end2)) || (gdt.after(freeze_date_start3)&&gdt.before(freeze_date_end3))) {
				gs.log("Within the freezed date schedule "+date_to_check);
				return 1;
			} else {
				gs.log("NOT in the freezed date schedule "+date_to_check);
				return 0;
			}
		} else {
			return 0;
		}
	},
	type: 'Check_freeze_dates'
});