Flow Designer Action to add number of days (integer) to a date

Shilpa Mannoni1
Tera Contributor

Can anyone help me with the script for an action where the number of days can be added to the date.

Input: Date, No of days

Output: Date

Script needs to: add Date + No of days and return date

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Shilpa Mannoni1 Here is the custom action for you which takes two parameters Date and number of days and add the days to date and returns the updated date.

 

Screenshot 2023-05-09 at 1.42.00 PM.pngScreenshot 2023-05-09 at 1.42.22 PM.pngScreenshot 2023-05-09 at 1.42.42 PM.pngScreenshot 2023-05-09 at 1.43.05 PM.pngScreenshot 2023-05-09 at 1.43.32 PM.pngScreenshot 2023-05-09 at 1.44.10 PM.png

Here is the script for run script.

(function execute(inputs, outputs) {
// ... code ...
  var someDate = new GlideDate();
  someDate.setValue(inputs.date);
  someDate.addDaysUTC(inputs.days);
  outputs.new_date = someDate;
})(inputs, outputs);

 

I am also attaching the update set which contains this Action.

 

Please mark this answer correct and helpful if it addresses your requirement.

 

View solution in original post

5 REPLIES 5

Sandeep Rajput
Tera Patron
Tera Patron

@Shilpa Mannoni1 Here is the custom action for you which takes two parameters Date and number of days and add the days to date and returns the updated date.

 

Screenshot 2023-05-09 at 1.42.00 PM.pngScreenshot 2023-05-09 at 1.42.22 PM.pngScreenshot 2023-05-09 at 1.42.42 PM.pngScreenshot 2023-05-09 at 1.43.05 PM.pngScreenshot 2023-05-09 at 1.43.32 PM.pngScreenshot 2023-05-09 at 1.44.10 PM.png

Here is the script for run script.

(function execute(inputs, outputs) {
// ... code ...
  var someDate = new GlideDate();
  someDate.setValue(inputs.date);
  someDate.addDaysUTC(inputs.days);
  outputs.new_date = someDate;
})(inputs, outputs);

 

I am also attaching the update set which contains this Action.

 

Please mark this answer correct and helpful if it addresses your requirement.

 

Thank you so much @Sandeep Rajput . This worked perfectly.

Bret Smith
Giga Guru

Catalog Client Scripts

Need By Date Plus 14 Days From Today
OnChange
Variable Name: general_need_by_date

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

var today_dateStr = formatDate(new Date(),g_user_date_format);
var todayNum = getDateFromFormat(today_dateStr,g_user_date_format);
var fourteen_days_from_today = new Date();
fourteen_days_from_today.setDate(fourteen_days_from_today.getDate()+14);
var fourteen_days_from_todayStr = formatDate(fourteen_days_from_today,g_user_date_format);
var fourteen_daysNum = getDateFromFormat(fourteen_days_from_todayStr,g_user_date_format);
var newValueNum = getDateFromFormat(newValue,g_user_date_format);
//alert ('todayNum: ' + todayNum);
//alert ('14_days_from_today: ' + fourteen_days_from_today);
//alert ('14_daysNum: ' + fourteen_daysNum);
//alert ('newValueNum: ' + newValueNum);
if(newValueNum < todayNum || newValueNum < fourteen_daysNum) {
g_form.addErrorMessage('"Need by date" must be at least 14 days from today: ' + fourteen_days_from_todayStr);
// alert('14 days from today is ' + fourteen_days_from_todayStr);
g_form.clearValue('general_need_by_date');
}
}

That script is for the Catalog Item (not for Flow Designer)