Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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 ACCEPTED SOLUTION

Create a schedule that has a recurring tuesday 9am-12pm schedule entry. Then before your create catalog task action add a wait for duration. Use explicit duration 1s and during the aforementioned schedule.

This way if you are outside the window it will wait until the window opens to start the duration. And if you are inside the window it will start counting instantly

View solution in original post

6 REPLIES 6

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

@SiddharthN62887 

Hope you are doing good.

Did my reply answer your question?

šŸ’” 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

with this logic, we can make flow to wait until a specific time. But my requirement is to create task in a specific time window like (tuesday 9am to 12pm).

Create a schedule that has a recurring tuesday 9am-12pm schedule entry. Then before your create catalog task action add a wait for duration. Use explicit duration 1s and during the aforementioned schedule.

This way if you are outside the window it will wait until the window opens to start the duration. And if you are inside the window it will start counting instantly