Add number of days from date RITM is approved and derive that date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 08:26 AM
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.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 01:40 PM
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
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 09:33 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader