We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

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

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

@Community Alums Please refer to this thread https://www.servicenow.com/community/developer-forum/trying-to-set-a-due-date-in-flow-designer-to-a-... it answers the same question.

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?