- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2021 09:27 PM
Hello,
I need help. I am trying to use Catalog UI Policy to set the condition on the end date field. What I need is the end date cannot be before start date.
The field is "date" not "date/time"
I applied the condition as below for "end_date_of_visit" is more than 0 days after "starting date of visit" and use the client script BUT it doesn't work. The end date of visit field still can fill in the date before starting date.
Not sure that for this case, it's wrong on the condition I set or from the client script ?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2021 10:33 PM
Hi,
Have you tried an alternative with the onchange client script on end_date.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var dFormat = g_user_date_format;
var end = getDateFromFormat(g_form.getValue('end_date'),dFormat);
var sDate=getDateFromFormat(g_form.getValue('start_date'),dFormat);
if(end<sDate)
{
alert(getMessage("End date should not be before Start date"));
g_form.setValue('end_date','');
}
}
Please mark Correct✅/helpful???? if applicable, thanks!!
Aman

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2021 09:46 PM
I don't think getMessage will work in your script.
Comment line 2, and check

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2021 10:11 PM
Hi,
Here you can use client script and script include as well.
onChange of "End Date" field.
Use GlideAjax and Script include for this.
For Example : If i want to check "Start date should not be greater than end date" if yes then show alert or any message "do not submit" and if not then it will show "submit it".
Client script will be like:
var ga = new GlideAjax('scriptinclude_name');
ga.adddParam('sysparm_name',function_name);
ga.addParam('sysparm_sysid',sysID);
ga.addParam('sysParm_newValue'newValue);
ga.getXML(callbackfunction);
function callbackfunction(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer=='do not submit")
{
alert("enter start date smaller than end date");
callback(false);
}
else if(answer=="submit it")
{
var confirmation=confirm("Are you sure want to change start date?");
callback(true);
}
}
Script Include:
sunction_name function()
{
var newDate = this.getParameter('sysParm_newValue');
var gr=new GlideRecord('incident');
ge.addQuery('sys_id',thiis.getParameter('sysparm_sysid'));
gr.query();
if(gr.next())
{
if(newValue>gr.u_end_date)
{
return "do not submit";
}
else if(newVallue<=gr.u_end_date)
{
return "submit it";
}
}};
Please try to do same with your condition.
If it is helpful then please don't forget to mark it as helpful or correct.
Thank you,
Sanika Gaikwad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2021 10:18 PM
Hi,
did you just hard-coded the message in the showErrorBox
I think the condition looks good.
Regards
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
‎04-29-2021 10:31 PM
I modified script to be like this but still no error box.
function onCondition() {
g_form.showErrorBox('end_date_of_visit',"End date of visit can't be before Starting date of visit.",'error');
return;
}