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.

veera11
Kilo Explorer

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.

find_real_file.png

 

find_real_file.png

whenever i fill the details of "issue dated on" and Issue "Resolved on" then only the alert should be displayed.

6 REPLIES 6

p t1
Kilo Sage
Kilo Sage

Hi ,

 

if(issuestartdate != '' && resolvedate != '' && issuestartdate < resolvedate)

 

Try this condition..

 

Thanks,

Preethi

asifnoor
Kilo Patron

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.

https://community.servicenow.com/community?id=community_article&sys_id=a26dac761b4e8010a59033f2cd4bc...

Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.

Regards,
Asif
2020 ServiceNow Community MVP

Aniket Sawant
Mega Expert

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.

 

 

Prithviraj Howa
Kilo Expert

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