fill a date on a form based in other field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I have two fields: Start Date and Initial Date, both of type Date (not Date/Time).
When the user selects the Group "PANP", I need the Initial Date to be automatically set to 1 month and 7 days after the selected Start Date.
I’ve already tried using a Script Include and a Client Script (onChange), but either it doesn’t work, or it behaves incorrectly — for example, if the Start Date is 12/03/2025, it reads it as December 3rd instead of March 12th.
We use the day/month/year format.
Has anyone done something similar or knows how to make this work properly?
Thanks in advance,
Marisa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
41m ago
Hi @MARISA INACIO1,
To achieve your requirement where the Initial Date is automatically set to 1 month and 7 days after the Start Date when the Assignment Group is PANP, the most reliable and maintainable solution is to make Initial Date a calculated field.
- Navigate to the Dictionary Entry for the field Initial Date (u_initial_date) in the Requested Item (sc_req_item) table.
- Under the Calculated Value tab:
- Calculated: Checked (true)
- Calculation type: Script
- Calculation script:
(function calculatedFieldValue(current) {
if(current.assignment_group.name == 'PANP'){
var startDate = new GlideDate(current.u_start_date);
startDate.addMonths(1);
startDate.addDays(7);
return startDate;
}
return current.u_initial_date;
})(current);
Important Notes:
- Ensure your Start Date (u_start_date) is of type Date, not Date/Time.
- The calculation will only apply when the record is created or updated server-side.
- GlideDate handles the date formatting internally, so you don’t need to worry about the day/month/year interpretation issue.
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
31m ago
it's possibly because of the date format.
share your client script and script include here.
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