ScTask must be create only in a specific time window.

SiddharthN62887
Tera Contributor

Hi All, I was working on a flow designer logic, and getting a problem in it.
My requirement is: users can raise their request at any time but sctask should only be create in a specific time window.

For Ex:- user raised a req on thursday, even after getting approval ScTask should create on  tuesday between (9am to 12pm).
To implement this, I've added a wait for condition in my flow just before first scTask:

 
var region = fd_data.trigger.request_item.variables.region;

var now = new GlideDateTime();
var day = now.getDayOfWeek();
var val = now.getValue(); // 'yyyy-mm-dd hh:mm:ss'
var hour = parseInt(val.substring(11, 13), 10);
var min = parseInt(val.substring(14, 16), 10);

function isTimeBetween(startHour, startMin, endHour, endMin){
    var nowMinutes = hour * 60 + min;
    var startMinutes = startHour * 60 + startMin;
    var endMinutes = endHour * 60 + endMin;

    gs.log('function is executed: nowMinutes: '+ nowMinutes +' startMinutes: '+startMinutes+ ' endMinutes: '+ endMinutes);

    if(startMinutes <= endMinutes){
        return nowMinutes >= startMinutes && nowMinutes <= endMinutes;
    }
    else
        return nowMinutes >= startMinutes || nowMinutes <= endMinutes;
}

if(day == 2){

    if(region == 'UK_VBLOCK' || region == 'UK_Nutanix' || region == 'US' || region == 'BR')
    {
        gs.log('flow is in if condition');
        answer =  isTimeBetween(1, 50, 2, 30);
   
    }
    else if(region == 'SGHP2_VBLOCK' || region == 'AP_SGHP2_VBLOCK' || region == 'SG_Nutanix_EQ' || region == 'JP' || region == 'HK' || region == 'AU')
    {
        answer = isTimeBetween(13, 0, 15, 0);
    }
}
answer = false;


But (wait for) action is not checking time in real time, it is only checking when there is a record update, which is making it a wrong approach. Please let me know if I can try something else here.
1 REPLY 1

Ankur Bawiskar
Tera Patron

@SiddharthN62887 

Don't use Wait for condition, it requires update on the record.

You should use Wait for Duration and specify till when it has to wait and then proceed

check this and enhance

ServiceNow Flow Designer - Make api call 3 days before the start date 

basically get the 9am time of Tuesday and make your flow wait till then

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader