Set End date field to one year

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 07:52 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 08:12 AM
@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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2025 02:33 AM
@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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2025 03:24 AM
@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.
--