- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2022 01:29 AM
Hello Everyone,
Please help me with this usecase.
Create new variable type - Date,
Name - Implementation Date.
Validation - Date selected should be within 5 business days.
If not,
show error message and clear value.
note:If i select a date that is on saturday or sunday if should show error message and clear the value. The five business days should only get inserted in the catalog item.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2022 02:00 AM
Hi
Please refer below Client script to get day of Week. Replace date with your date field.
You can use this in the UI policy also.
var df = g_form.getValue('u_date');
var op=df.split('/');
var ress=op[2]+'/'+op[1]+'/'+op[0];
var objdate=new Date(ress);
alert(objdate);
var selday=objdate.getDay();
var res = parseInt(selday);
alert(res);
if(res==0||res==6)
{
alert('select business day');
}
Thanks,
Please mark the answer as correct and helpful.. If answer is feasible.
Please mark the answer as helpful and correct.
Best Regards,
Rajat Choudhary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2022 02:00 AM
Hi
Please refer below Client script to get day of Week. Replace date with your date field.
You can use this in the UI policy also.
var df = g_form.getValue('u_date');
var op=df.split('/');
var ress=op[2]+'/'+op[1]+'/'+op[0];
var objdate=new Date(ress);
alert(objdate);
var selday=objdate.getDay();
var res = parseInt(selday);
alert(res);
if(res==0||res==6)
{
alert('select business day');
}
Thanks,
Please mark the answer as correct and helpful.. If answer is feasible.
Please mark the answer as helpful and correct.
Best Regards,
Rajat Choudhary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2022 08:50 PM
Hi Rajat,
Thank you for your suggestion its working.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2022 09:04 PM
Can you explain me what 2,3 line means
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2022 02:50 AM
Hi
You can either adapt the below into a Scripted UI Policy or use as an onChange Client Script.
Client Script (onChange):
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Call the GA function
var gaDateDiff = new GlideAjax('ClientDateTimeUtils');
gaDateDiff('sysparm_name', "getNowDateTimeDiff");
gaDateDiff('sysparm_date', g_form.getValue('implementation_date_field'));
gaDateDiff(function(answer){
if(answer == ‘false’){
g_form.clearValue('implementation_date_field');
g_form.showFieldMsg('implementation_date_field', "Date should be within 5 business days from today." , 'error');
}
});
}
Script Include:
var ClientDateTimeUtils = Class.create();
ClientDateTimeUtils = Object.extendsObject(AbstractAjaxProcessor, {
getNowDateTimeDiff: function(){
var dateSelected = this.getParameter('sysparm_date');
var nowDateTime = new GlideDateTime();
var days = 5;
var dur = new GlideDuration(days*43200*1000);
// paste the sys_id of the ‘8-5 weekdays excluding holidays’ schedule excluding holidays
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828'); //8-5 weekdays excluding holidays
var finalTime = schedule.add(nowDateTime, dur,'');
var updatedGdt = new GlideDateTime(dateSelected);
var finalTimeGdt = new GlideDateTime(finalTime);
if(updatedGdt < finalTimeGdt){
return 'true';
}
return 'false';
},
type: 'ClientDateTimeUtils'
});
To help others, please mark this as correct and/or helpful.
Thanks,
Robbie