Set End date field to one year

Community Alums
Not applicable

Hi All, 

 

Having a requirement that, on the catalog form we have a catalog form with the start and end date fields. 

when the form loads the end date field is non-mandatory. while submitting the form if the end field is not selected any date we need to set it to default to one year. or if the date is selected then the selected date value should pass. 

 

Need suggestion to achieve this. 

 

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

then if end date is not submitted/populated after submission you can use script and set the value

simple way is to use after insert BR on sc_req_item with condition as c

current.cat_item.name == 'Your Catalog Item Name Here' && current.variables.end_date == ''

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var nowTime = new GlideDateTime();
nowTime.addYearsUTC(1);
current.variables.end_date = nowTime.getValue();
current.update();

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Community Alums 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

SupriyaWaghmode
Kilo Sage

@Community Alums ,

 

1. On select start date you have to auto-populate End date as @Ankur Bawiskar mentioned in the code.

2.Also you can make end date mandatory( if its suitable for use case ) which will make sure that end field is added alternative option you can use below code.

 

--

Thanks & Regards ,
Supriya Waghmode |ServiceNow Consultant