Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Flow Designer InLine Script for Field Assignment

meganmwright18
Tera Contributor

Hello Community! I am working in flow designer right now, within a 'create catalog task' action step. See in this, for the field 'due_date' I have the assignment scripted instead of from dot-walking or the dropdown/reference. What I need to do here is pull in the date that the user entered in the item/form submitted and compare that to the current date. If it's in the past or within 2 days from today, the due_date field in the created task should be 2 days from now. But then if the date that the user entered is more than 2 days from the current date, then the due date should just be set to 2 days prior to the entered date. And I would like the time for the due_date to always be set to 17:00:00(5pm) local time for the person viewing the task. 

The problem > There is something wrong with my script, I can save my changes in flow designer but when I try to activate the flow I get the error 'Index 1 out of bounds for length 1'. I can't seem to figure out what this means. I would appreciate any help, ideas, or guidance ((: 

meganmwright18_0-1749063822760.png

meganmwright18_1-1749063859452.png

 

var startDateString fd_data._1_get_catalog_item_variables.start_date_at_this_property;
var startDate = new GlideDateTime(startDateString + " 00:00:00");
startDate.setHourLocalTime(0);
startDate.setMinuteLocalTime(0);
startDate.setSecondLocalTime(0);

var now = new GlideDateTime();
now.setHourLocalTime(0);
now.setMinuteLocalTime(0);
now.setSecondLocalTime(0);

var diffInMillis = startDate.getNumericValue() - now.getNumericValue();
var diffInDays = Math.floor(diffInMillis / (1000 * 60 * 60 * 24));

var due_date = new GlideDateTime();
if (diffInDays <= 2) {
  due_date.addDaysLocalTime(2);
} else {
  due_date = new GlideDateTime(startDate);
  due_date.addDaysLocalTime(-2);
}

due_date.setHourLocalTime(17);
due_date.setMinuteLocalTime(0);
due_date.setSecondLocalTime(0);

gs.info("returned due date: " + due_date);
return due_date;

 

*Details: 

- The start_date_at_this_property variable is type date

- The due_date field on the task record is date/time

 

 

1 ACCEPTED SOLUTION

J Siva
Kilo Patron
Kilo Patron

Hi @meganmwright18 
In your script, the first line should be,

var startDateString = fd_data._1__get_catalog_variables.start_date_at_this_property;
It should be_1__get_catalog_variables not _1_get_catalog_item_variables

Hope this helps.
Regards,
Siva
 

View solution in original post

2 REPLIES 2

J Siva
Kilo Patron
Kilo Patron

Hi @meganmwright18 
In your script, the first line should be,

var startDateString = fd_data._1__get_catalog_variables.start_date_at_this_property;
It should be_1__get_catalog_variables not _1_get_catalog_item_variables

Hope this helps.
Regards,
Siva
 

That did finally make the date change! Now troubleshooting issues with the time setting but am thankful to be over the date-change hump. Of course it was something like just an extra '_' haha