Catalog UI Policy - end date cannot be before start date

Bird Petcharayu
Kilo Contributor

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 ?

 

find_real_file.png

 

find_real_file.png

1 ACCEPTED SOLUTION

Aman Singh_
Kilo Sage

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

View solution in original post

20 REPLIES 20

AnirudhKumar
Mega Sage
Mega Sage

I don't think getMessage will work in your script.

Comment line 2, and check

Sanika Subhash
Tera Expert

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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

did you just hard-coded the message in the showErrorBox

I think the condition looks good.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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;
}