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

Add number of days from date RITM is approved and derive that date

Arka Banerjee1
Tera Contributor

Hi All,

 

I have a requirement where I need to add a certain number of days based on the value selected on a catalog item form from the date when the RITM is fully approved, and then convert the date by adding the number of days to the approved date in a date format and send it over a JSON. Can someone please help me on how I can derive the date.

 

@Ankur Bawiskar 

 

Thanks!

2 REPLIES 2

Chaitanya Redd1
Tera Guru

Hi,

Create catalog client script as below and Map the Date Field in the JSON Payload

function onSubmit() {
    // Get the selected number of days
    var daysToAdd = g_form.getValue('days_to_add');
    
    // Get the approved date from the form
    var approvedDate = g_form.getValue('approved_date');
    
    // Convert the approvedDate to a GlideDateTime object
    var approvedDateTime = new GlideDateTime();
    approvedDateTime.setDisplayValue(approvedDate);

    // Add the selected number of days to the approved date
    approvedDateTime.addDaysUTC(daysToAdd);
    
    // Convert the result back to a formatted date string
    var newDate = approvedDateTime.getDisplayValue();

    // Set the new date back to the form field
    g_form.setValue('new_date_field', newDate); // Replace 'new_date_field' with your actual field name

    return true; // Continue form submission
}

After you've calculated the new date, you can include it in your JSON payload. You can add it as a field in your JSON object

var jsonData = {
    "new_date": newDate // Replace with the appropriate field name in your JSON payload
};

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Arka Banerjee1 

so you want to add days to date variable?

without screenshot and without the script you started it will be difficult for me to help.

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