Flow Designer Waits: When a Second isn't a Second

Flow Designer, if you havenā€™t heard from me, is a great tool in the ServiceNow platform. It makes process automation, prototyping and no-code development so fast and easy. Sure, it has itā€™s flaws, but who doesnā€™t?

What if I told you, when you asked Flow Designer to do something SO SIMPLE as ā€œwaitā€ for 1 second, it (almost) literally LAUGHED AT YOU and did WHATEVER THE HECK IT FELT LIKE?

The Reason

I have a flow which calls an API to send a push notification to our 2FA (Okta). It works great, you get the push, happy days. BUTā€¦

We then need to check another endpoint to see what the userā€™s response was, and because itā€™s a real person, not some kind of BUTTON PUSHING ROBOT - that can take a while. In the worst-case of a user IGNORING the push, it expires after a fairly long period of time (5 minutes!)

I wrote a 1 second wait into a loop, so at worst, we send 300 polls to the endpoint. It was a quick-and-dirty option, alright?

BUTā€¦ and hereā€™s where the issue appears. Those waits are taking forever. Enter my tests:

The Setup

Iā€™m running the tests in my Personal Developer Instance, on Orlando Patch 1. The flows have been made in Global Scope, and called via API from Background Scripts.

Hereā€™s my basic test flow:

I was planning on doing a lot more testing (scope vs global, during loops or not, etc), but I donā€™t think there was much merit in it.

I wanted to compare waits during:

startFlow vs startFlowQuick and

executeFlow vs executeFlowQuick

These all should be Asynchronous and in theory, write two work-notes to a job a second apart. Letā€™s see what happenedā€¦

The Results

Control - Test Without a Wait

No Wait Execution

No Wait Baseline

The flow ran, and it looks to take in the 10ā€™s of milliseconds. Thatā€™s visible in the second update where itā€™s flicked from one second to the next. Thatā€™s OK with me!

Flow, Executed by ā€œTestā€ w/ 1sec Wait:

1sec Flow

  • 1: 6 seconds
  • 2: 8 seconds
  • 3: 8 seconds
  • 4: 9 seconds
  • 5: 4 seconds
  • avg = 7 seconds šŸ˜¦

Flow, async script (startFlow):

1sec Async

  • 1: 7 seconds
  • 2: 9 seconds
  • 3: 10 seconds
  • 4: 9 seconds
  • 5: 8 seconds
  • avg = 8.6 seconds šŸ˜¦šŸ˜¦

Flow, async script (startFlowQuick):

1sec Async Quick

Hereā€™s something interesting - doing a Quick never reaches past the ā€œWaitā€ - even though itā€™s called ASync. Also, it runs as the system user? Who uses this ā€œquickā€ method and WHY!?

Flow, sync script (executeFlow):

1sec Sync

  • 1: 5 seconds
  • 2: 2 seconds
  • 3: 9 seconds
  • 4: 7 seconds
  • 5: 5 seconds
  • avg = 5.6 seconds šŸ˜¦šŸ˜¦šŸ˜¦

Flow, sync script (executeFlowQuick):

1sec Sync Quick

Another interesting note - Running a Synchronous script using the executeFlowQuick actually threw an error in the Background Script editor:

Flow Designer: Persisting an unterminated plan is not supported for plan with id null and name: Global Flow Wait Test: no thrown error

This also runs as yourself, vs the System user the ASync one runs as, but still doesnā€™t work.

Flow, 10 second wait

For funsies I even changed the wait to 10 seconds to see if it would get a little more tight.

10s Wait

  • 1: 18 seconds
  • 2: 15 seconds
  • 3: 13 seconds
  • 4: 21 seconds
  • 5: 12 seconds
  • avg = 15.8 seconds šŸ˜¦

Outcomes

Well, the outcomes are NOT GOOD. I am disapointed this is the case, and will have to re-engineer or just accept that we are going to use a lot more (without a wait) / less (with a wait thatā€™ll take too long) API calls than we thought.

The Fix(?)

Hereā€™s the magic, right?

Look at this: 1 second

and this: Hard wait

and this: hard wait output

and THIS!: hard wait worknotes

BUT! DUN DUN DUN

We canā€™t have nice things.

The magic I was using to get this exact second is the UNMENTIONABLE HORROR that is gs.sleep(1000)

Sleep Date/Time

Step HardWait

And every time that runs, it locks a whole thread in your instance. And thatā€™s just not something we can do in Production. No matter how badly we want it, it just feels icky.

The TL;DR

  • Flow Designer ā€œWaitsā€ are all crazy asynchronous things that take far too long. Donā€™t wait for 1 second. Itā€™s more likely 10.
  • The ā€œQuickā€ options in the API donā€™t really work with waits
  • Sync or ASync doesnā€™t matter at the flow level
  • 1 second or 10 seconds doesnā€™t matter either
  • hard-sleeping a thread works, BUT AT WHAT COST!?
  • Just deal with it I guess?

Sorry I couldnā€™t be more help. Itā€™s interesting data though, right?

ā¤ļø Andrew


Share on:
comments powered by Disqus