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

Thanks, It worked for me.

lauri457
Tera Sage

Just curious, what would be the reason for this requirement?