Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

While Loop On Section of Workflow

gmacd
5 - Atom

Hello,

 

I've been pouring over the community to try to find a solution to what I'm looking for but can't find quite the right solution. 

 

I'm building an app that makes a series of API calls where each call takes inputs from the parsed JSON responses of the previous call ultimately coming to a call that results in a long running operation on the server.  This long running operation creates a resource that can be polled to get the operation's status at whatever interval until the operation is complete. In the JSON response it will give me either 'IN_PROGRESS', 'COMPLETED', or 'FAILED'. 

 

What I'd like to do is create a section of the workflow that will repeat as long as the status returned from the call is 'IN_PROGRESS' and exit once the status is either 'COMPLETED' or 'FAILED' then I'll handle each those conditions as needed.  Most of the solutions around this kind of thing rely on iterative macros but this process isn't iterative. 

 

In pseudo code:

 

var status = makeApiCall();

while (status == 'IN_PROGRESS') {

     status = makeApiCall();

 

This is the section I want to repeat and how I tried it.  I get why it won't work but it illustrates what I'm looking to do.  Select nabs certain fields from upstream, append just passes through, the formula prepares certain fields for the API input.  The macro then makes the API call, then I'm selecting a specific value from the response, and testing the value. What I want to do is if True go back to the beginning and rerun the  API call.  Keep doing that until it's false which I'll then handle.  Bonus if I can tell it to wait a certain number of seconds before trying again.

clipboard_image_2.png

 

Apologies for being wordy since I didn't share the workflow.

 

Also, apologies for not sharing the workflow since I've hard coded API credentials into it while I'm testing.

1 REPLY 1
danilang
19 - Altair
19 - Altair

Hi @gmacd 

 

You mention that your process isn't iterative, but it actually is since you're trying to repeat(iterate over) a section of the workflow until some condition is met, i.e. a While loop.  Since the Alteryx engine doesn't allow you to backtrack in a workflow, you'll need to look at a macro-based solution.  You think you need a While loop (I agree) so you should look at an iterative macro.  An iterative macro loops until a condition is reached, in your case receiving an 'COMPLETED' or 'FAILED' result.  The connection in your code that reaches back from the Filter to the Append Fields tool is what the Iterative Output in the macro recreates in a way that allows the engine to pass results back into a point that is upstream. 

 

 A good starting point is this video from Alteryx's own @JoeM

 

Dan

Labels