Flow Designer - Wait for a duration of time (localised time zone)

TJ29
Tera Contributor

We have a flow that waits for 18 hours to disable an account at 6PM but it does it based on the system time of GMT. We'd like this to be localised so US users get theirs at 11PM GMT / 6PM EST.

 

Is there a way to do this in flow designer without having to an IF for each location?

4 REPLIES 4

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi TJ,

I haven't checked this but which user is the flow being executed with? If the flow is being executed by System User, the time probably would be in UTC.

  1. Click on ellipsis at the top right corner and select "Properties"
    find_real_file.png
  2. Check "Run As". 
    find_real_file.png

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi, re-read the question and may not be understanding it fully.

>We'd like this to be localised so US users get theirs at 11PM GMT / 6PM EST.

>Is there a way to do this in flow designer without having to an IF for each location?

Does this imply convert user's time to EST and then delete the account if it's 6PM EST?

If so, I'll do as follows.

  1. Set the flow to trigger every hour
  2. Have a lookup records to get potential users to disable
  3. Use For each loop to process each user
  4. Have lookup record to get user's record
  5. Get user's time zone and convert the time to EST
  6. Check if the converted time is 18 hours since the record to disable user has been updated
  7. If it's more than 18 hours, disable the account

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi,

I really haven't tested this but something like below.

I've created 1 flow and 2 actions. One action to convert time zone and another action to compare dates. 

find_real_file.png

In step 3, to convert time, I've written a script to get the current date at 6pm. I'm converting today at 6pm in user's time zone to time in EST (America/New_York) taking into account Day light saving time as well.

var gd = new GlideDate();
var today = gd.getDisplayValue();
var gdt = new GlideDateTime();
gdt.setDisplayValue(gd.getDisplayValue() + ' 18:00:00');
return gdt.getDisplayValue();

find_real_file.png

Action to compare time if the returned time is on or after current time.

find_real_file.png

And then have an if condition.

find_real_file.png

Following is the input to Action to convert time.

(function execute(inputs, outputs) {
  var expectedTimezoneDateTime=new   GlideScheduleDateTime(inputs.datetime).convertTimeZone(inputs.fromtimezone, inputs.totimezone);
  var convertedTimeZoneDateTime= new GlideDateTime(expectedTimezoneDateTime);
  outputs.datetime = convertedTimeZoneDateTime;
})(inputs, outputs);

 

find_real_file.png

Following is an action to compare time.

(function execute(inputs, outputs) {
try {
  var gdtCheck = new GlideDateTime(inputs.datetime);

  gdtCheck.add(inputs.hours * 60 * 60 * 1000);
  var hoursAgoNum = gdtCheck.getNumericValue();
  
  var gdtNow = new GlideDateTime();
  var nowNum = gdtNow.getNumericValue();
  
  outputs.hoursagonum = hoursAgoNum;
  outputs.nownum = nowNum;
  
  if (hoursAgoNum >= nowNum) {
      outputs.isafter = true;
  } else {
    outputs.isafter = false;
  }
} catch (e) {
  outputs.error = e.message;
}
})(inputs, outputs);

find_real_file.png

Hi Hitoshi


Thanks for this - I'll give it a test. We basically have a leavers process that disables their AD account at 6PM but the current limitation means all locations get their account disabled at 6PM GMT rather than localised. As an interim I've created a subflow that looks up their location and waits for a set amount of time. New York = 23 hours, Sydney = 9 hours etc. 

 

Will see how I get on with applying your logic potentially.