The CreatorCon Call for Content is officially open! Get started here.

fill a date on a form based in other field

MARISA INACIO1
Tera Contributor

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?

 

MARISAINACIO1_2-1759482586108.png

 

 

Thanks in advance,

Marisa

 

3 REPLIES 3

Anand2799
Tera Guru

Hi @MARISA INACIO1 ,

 

Could you provide screenshot of your script?

 

Thanks

Anand

M Iftikhar
Giga Sage

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);
MIftikhar_1-1759486413135.png

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.
MIftikhar_0-1759486376798.png

Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.

Ankur Bawiskar
Tera Patron
Tera Patron

@MARISA INACIO1 

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.

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