I have created a onSubmit() client script in Incident form here my requirement is something whenever i select issue opened start date is greater then issue Resolved date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2020 10:19 PM
Hi,
I have created a onSubmit() client script in Incident form here my requirement is something whenever i select issue opened start date is greater then issue Resolved date.
But when i am submitting the form without filling those details still i am getting the alert message.
whenever i fill the details of "issue dated on" and Issue "Resolved on" then only the alert should be displayed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2020 10:27 PM
Hi ,
if(issuestartdate != '' && resolvedate != '' && issuestartdate < resolvedate)
Try this condition..
Thanks,
Preethi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2020 10:31 PM
Hi,
You are getting alert, becuas you have placed alert in both if and else conditions. So in either case, you get an alert. Kindly keep alert only inside if and remove from else.
Also for date manipulations, it is best to convert in date format and check. Here is the article with samples. check this out.
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2020 10:44 PM
Hi,
You can achieve this by using UI POlicy
So it will validate at client side before any update or insert
In ui policy, In when to run tab you can select condition as
u_issue_start_date is more than u_issue_resolved_date
do not mention hours/day.
and in script type, as follows.
function onCondition() {
g_form.clearValue('u_issue_resolved_date');
g_form.showFieldMsg('u_issue_resolved_date',"Issue start date should be less than issue end date",'error');
}
Please mark correct or helpful based on the impact.
Regards,
Aniket Sawant.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2020 10:47 PM
Hello Veera,
function onSubmit()
{
var issuestartdate=g_from.getValue('u_issue_dated_on');
var resolvedate=g_form.getValue('u_issue_resolved_on');
if(issuestartdate > resolvedate )
{
alert("Issue dated on is grater than of issue resolved on date");
return false;
}
else if(issuestartdate < resolvedate )
{
alert("form will submit because resolved date is greater than issue date");
}
else(issuestartdate == resolvedate )
{
alert("Form will submit because date is equal to issue date");
}
}
Please mark reply as Correct and Helpful, if applicable. Thanks!
If not please let me know.
Warm Regards,
Prithviraj Howal
SNOW Developer