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.

Populate form field value based on variable value using Flow designer script

Community Alums
Not applicable

Hello,

We have a requirement to populate value in the Due date field (Form field) based on value available in the variable field(date/time). It should set Due date to be after 5 days of variable value. This should be achieved using flow designer.

We tried using following script but it's not working. Please help us to correct it.

 

var disableDate = fd_data.trigger.request_item.variables.variable_name;
var days = 5;
//assuming there are 8 business hours
days = days*8;
var dur = new GlideDuration(60 * 60 * 1000 * days);
var schedule = new GlideSchedule('0aa442ea6fbc92006e652091be3ee48e'); //put your schedule sys_id here
var end = schedule.add(disableDate, dur);
return end;

 

 

Regards,

Jainil

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

Community Alums
Not applicable

@Sandeep Rajput  We tried replicating the similar script but it displays error:

Here is the script.

var disableDate = fd_data.trigger.request_item.variables.variable_name;
var gdt = new GlideDateTime();
gdt.setValue(disableDate);
var businessDaysToAdd = 5;
var hoursToAdd = businessDaysToAdd * 8;
var duration = new GlideDuration(hoursToAdd * 60 * 60 * 1000);
gdt.add(duration);
return gdt.getValue();
 

@Community Alums Could you please share the details on the error you are seeing?