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.

Compare future value in Due date(in Task A) with current Date time and if matches then create Task B

Rekha10
Tera Contributor

I need to create Task B in a custom table (In custom app) when either of the following conditions are met:

STC_flag = Yes and Next Activity = Y, OR STC_flag = Yes and the Due Date/Time of Task A equals the current date/time.

Due date holds a future value, Code 1 is to capture that value.

Code1:

var gdt = new GlideDateTime();
return addBusinessDays(gdt,3);

function addBusinessDays(gdt, daysToAdd) {
var count = 0;

while (count < daysToAdd) {
gdt.addDaysLocalTime(1); // move forward one day

// 1 = Monday … 7 = Sunday
var dayOfWeek = gdt.getDayOfWeekLocalTime();

if (dayOfWeek != 6 && dayOfWeek != 7) {
// Not Saturday or Sunday → count it
count++;
}
}

return gdt;

I have created an Action in flow designer to capture current date and time, mention in Code 2:

(function execute(inputs, outputs) {
    outputs.now = new GlideDateTime().getValue();
    return outputs;
})(inputs, outputs);
 
In flow designer I used action "wait for condition" to compare Due date and Variable in custom action, expectations are that when they match then Task B should create but it didn't work, below is FlowDesigner screenshots of action, flow and test flow execution. 
Please advise the solution, how to achieve this

 

 

1 REPLY 1

adityahubli
Tera Contributor

Instead of ding by flow you can do this  in Business rule to check date as well as create new task

var gr = new GlideRecord("task_a');
gr.addQuery('stc_flag', 'Yes');
gr.addQuery('due_date', '<=', new GlideDateTime());
gr.query();

while (gr.next()) {
var child = new GlideRecord('task_b');
child.initialize();
child.parent = gr.sys_id;
child.insert();gr.stc_flag = 'Processed';
gr.update();
}

 

if this helps you then mark it as help gull and accept solution,

Rgards ,

Aditya