- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 11:30 AM
Hi,i need a Catalog client script or an alternative solution that takes the value of a Date field on the catalog item and returns an error message if the chosen date is a Saturday or Sunday.
Thanks
I tried this but not working :
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 12:11 PM
Hi there @Francesco15
Try this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var date = new Date(newValue);
var dayOfWeek = date.getUTCDay(); /
if (dayOfWeek === 0 || dayOfWeek === 6) { /
g_form.addErrorMessage('Datum ist kein Werktag');
g_form.clearValue('u_datum_der_vereinbarung');
} else {
return true;
}
}
If this helps kindly accept the answer thanks much.
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
Microsoft MVP (AI Services), India
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 12:04 PM
Hi,
In my instance, using the above in a client script shows Saturday =5 and Sunday = 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 12:11 PM
Hi there @Francesco15
Try this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var date = new Date(newValue);
var dayOfWeek = date.getUTCDay(); /
if (dayOfWeek === 0 || dayOfWeek === 6) { /
g_form.addErrorMessage('Datum ist kein Werktag');
g_form.clearValue('u_datum_der_vereinbarung');
} else {
return true;
}
}
If this helps kindly accept the answer thanks much.
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
Microsoft MVP (AI Services), India
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 12:53 PM
Hi @Francesco15 ,
Your script is working correctly for me, tested in PDI
Selected 6th July 2024 Saturday
Selected 5th July Friday, No error msg appeared
Again, checked for 14th July 2024 Sunday
Please consider checking the format of date.
Mark this as Helpful / Accept the Solution if this helps
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 01:35 PM
You can easily debug the script, by adding and alert() as in:
var date = new Date(newValue);
//if(isNaN(selectedDate)){
var dayOfWeek = date.getDay();
alert('dayOfWeek = ' + dayOfWeek);