- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 11:12 PM
Hello,
I need to write a simple code to compare starting and ending dates in order to ensure the ending date is greater than the starting one.
This applies to a record producer which should be a catalog item at the same time - I have done similar task recently but I guess the catalog client script applied to a catalog item but not to a record producer (getting a bit confused here to be honest...).
Anyway previously I used this code and it worked but does not work in case of a record procducer (attaching snap shot of a record producer Date variable which I need to retrieve its value from and compare with another one).
OnChange client script I used previously but does not work at this time:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var start_date = getDateFromFormat(g_form.getValue('date_from'), g_user_date_time_format);
var end_date = getDateFromFormat(g_form.getValue('date_to'), g_user_date_time_format);
if (start_date > end_date) {
g_form.addErrorMessage('DATE TO must be greater than DATE FROM');
g_form.setValue('date_to','');
return false;
}
}
When I try to get value this way I get the result of zero, any hel on this?
Many thanks,
Milan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 11:19 PM
Hello Milan,
You can need to create a simple catalog UI Policy and Add a condition is
YourDateVariable BEFORE TODAY
Refer this docs for No Code date validations.
No Code date validations thru (Catalog) UI Policies
I will try to debug your code and share with you.
Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 11:18 PM
Hi,
Did you try adding alert whether if condition is getting satisfied?
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 11:19 PM
Hello Milan,
You can need to create a simple catalog UI Policy and Add a condition is
YourDateVariable BEFORE TODAY
Refer this docs for No Code date validations.
No Code date validations thru (Catalog) UI Policies
I will try to debug your code and share with you.
Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade
Abhishek Gardade

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 11:21 PM