Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Knowledge Base

Definitive answers from Designer Desktop experts.

Stop workflow on a condition

JordanB
Alteryx
Alteryx
Created

Sometimes you may want to stop a workflow if certain conditions are met!

Luckily within Alteryx we have the combination of the Test Tooland Workflow Propertiesto stop the workflow.

A common use case is you have scheduled workflow with an input file which is updatedeach week, but sometimes there is no new data. You would like to stop the workflow outputting and overwriting your output file if there are zero records in the workflow. In this particular use case you will want to add a count and test tool before your output tool to make sure no records pass to the output tool.

Adding a count tool will give you the value you need to see if any records are present in the workflow. If the count is 0 it means there no records present, if it greater than this there are records present and you would like the workflow to continue as designed.

When you attach the test tool to the count tool, you will need to hit the ‘Add’ button to create a test scenario.

Pic 1.png

When you hit add it will pop out another window.

Pic 2.png

In this window you can enter your test name which will populate in the results window error log. The input connection is the data stream. And the Test type reflects the type of test you would like to apply. In this particular example we will be using ‘Expression is True for All Records’.

Pic 3.png

The Test value field will give you a window similar to the formula tool. In here you can create your expression. The test tool workswhen a user-specified condition is not met. Therefore, the in this particular case I am looking for no data so having count less than 0 will errorwhen there is no data available.

Once you have configured the test tool and attached it in the workflow. You need to click on the canvas and navigate to ‘Runtime’ in the configuration window. In here there are a list of tick boxes, you will have to tick ‘Cancel workflow on error’. This will work in tandem with the test tool to cancel the workflow when the error is generated.

Here is a screenshot of the sample workflow.

Pic 4.png

I have also attached theexample workflow! (Built in Alteryx Designer v10.1)

Attachments
Comments
MPohlers
8 - Asteroid

Dear @JordanB.

 

is there also a way to not throw errors if a scenario is met. I am checking an API for updated data and everything works fine if there is new/ updated data. If there is nothing new however, I get an error and an email because of this error.

 

I would like to use the scenario you described but terminate the workflow right after this test without throwing an error.

 

The reasoning behind this is, that an error means something has gone wrong and I need to check my workflow. If a predefined scenario like "No Records" however is present I do not need to check because everything works like it is supposed to.

 

Best Regards

Martin Pohlers

JordanB
Alteryx
Alteryx

Hi @MPohlers

 

You can use the message tool instead of the test tool to select another message type other than error to satisfy your condition above.

 

Best,

 

Jordan Barker

Solutions Consultant

MPohlers
8 - Asteroid

Hello Jordan,

 

could you please provide an example?

 

I am not sure about the following points:

- How to set a condition like "Zero Records" in the message tool

- How to stop the workflow without throwing any error when this message is received

 

Best Regards

Martin Pohlers

FredericP
Alteryx Alumni (Retired)

I have exactly the same issue as @MPohlers, I need to stop gently without error a macro when no record is found, because of unpredictable APIs...

 

Also, your article does not explain which Workflow Property to set...

JordanB
Alteryx
Alteryx

Hi @MPohlers & @FredericP

 

In this scenario I would recommend using the Crew Macros and the conditional runner.

 

You can have one workflow which checks to see if the data has been updated. You can cause this workflow to fail if it doesn't need updating, and succeed if it does. This will avoid you getting errors in the master workflow.

 

In the second workflow you can have it set up to run the update URL workflow from the success node of the first conditional runner.

 

Capture.PNG

 

Best,

 

Jordan Barker

Solutions Consultant

 

 

SeanAdams
17 - Castor
17 - Castor

This is very useful @JordanB - thank you.  

Here is a case where I know the tool well, and have exactly this problem to solve (trying to deal with an error that is predictable in certain circumstances - the error happens when zero rows are returned from a dynamic query, so it's safe but still generates a messy outcome in the run logs) but never put 2 and 2 together to use the message tool to terminate the flow before the error without an error flag and thereby do a clean termination.

 

 

Sometimes just needs someone else's eyes on the problem

 

Thank you @JordanB - gonna use this today!

Shivang
5 - Atom

How to Change error message if directory tool does not found any file at given location?

My App return Error message.

Capture.PNG

 

I want to Change this error message

JordanB
Alteryx
Alteryx

Hi @Shivang

 

A user can first select the folder directory where the file resides. 

 

You can then have a user use a text input to update a filter looking for that file

 

You can then use a count tool to count the number of records coming out of the filter. This will tell you if that file exists or not.

 

Based on this you can add a message or test tool to say if [count]=0 then Error and say 'File not found' or whatever message you would like. 

 

In my example I have used a message tool, as I thought it would be cool to add the message in, however if that file exists then to allow the directory information to pass through so you can continue to read that data source in.

 

Filenot found.PNG

 

 

More description inside of the attached workflow (You will have to update the directory & filter tool to match your data)

 

workflow.PNG

 

Workflow built in 11.5

 

Best,

 

Jordan Barker

MGA
7 - Meteor

 Hi Jordan,

 

Thanks for posting, I was wondering if you have another example, or can help round

it out to a date based issue where we don't want a full workflow " cancel"but to split the process based on

true/false of some condition and handle it 2 ways. 

 

In this case, what if you have source 1 (and in data base connection) where you check

the max date called max_dt_source

 

Then you have source 2 (lets say your original output file)  that is max_dt_existing.

The business check would be IF max_dt_source > max_dt_existing then < run full process/ as a macro > 

else send an email saying "there was no new data for today". 

 

I have tried both options you listed above an my issues were as follows:

i can't use a 'test' since i don't want to cancel the workflow, i want it to send that email "no new data" for today

to the write people (alteryx server). I can't use the running crew macro since there is no other process that would be running.

I also tried an input macro and that doesn't work either. I currently have the workflow set up and append fields

and then compare the two dates. coming off the TRUE i have another check for the data is non null. coming off the false

i have the email all set up and ready to go. my issues is that even though there is only 1 record and 0 on the other side

both processes run. I also friend filters to ID a null, but it still runs both the FALSE and the TRUE process.

 

Thanks very much for your help,

 

Mallory

 

RaulO
5 - Atom

Hello, I have similar doubt about stop the workflow but, not generated by an error, I need a partial stop, I mean; I have a flow with two different ways to take, based on a filter, I need to stop totally the first way  if the filter take the second way or viceverse, stop totally the second way if the filter take the first way; thats because with the filter, the second option continue moving and create output files with empty info and I need to keep the originals until I run again and the conditions change to overwrite that files.

 

I tried Action Tool but I don't know how it works based on a condition coming from a filter.

 

Flow_to_stop.JPG

CameronS
Alteryx Alumni (Retired)

@RaulO - You will want to put the different paths inside a batch macro and use either detour tools or tool containers and actions to turn each section on and off with a control parameter.  Outside of the batch macro you can use either the filter tool or (maybe easier) a formula tool to pass a value into the control parameter of the macro which is then used to tell the action tool what to do. 

 

I suggest reading this article

RaulO
5 - Atom

Thanks CameronS,

 

I tried with the example in the article but I don't know how to aply it, I did some tests and changing my flow but alll the time goes in the same way, the condition could be false but anyways runs left.

 

Do you have some example that can share?, with action to close or disable the container tool.

saqibahmad
6 - Meteoroid

I have similar problem. I want my workflow to stop processing on No File Found.

1. Workflow has an email event - send email on error. to notify owner that workflow has failed.

2. if I fail workflow on my given condition using message tool - error and stop further processing, then event in step 1 triggers and send email which is undesirable.

 

I want event in step 1 triggers on workflow errors excluding user initiated error as in step 2.

 

Is there any way to control Events dynamically?

Say, on a given condition I can disable a Workflow Event?

Or may be Message Tool can have another option - Stop Processing without Error or Stop Processing with Warning

 

 

 

MPohlers
8 - Asteroid

@saqibahmad- this is what I am looking for, too!

SteveKnapper
8 - Asteroid

Hello, I have the same requirement in that I want to stop the workflow if no records.

The only issue I have is that I am using a batch macro, which I am chaining in a workflow with several others.

 

Stopping on the test results doesn't work within a batch macro as I don't then have the runtime tab.

 

I am also not using the crew macros as I schedule via the gallery

 

any advice would be much appreciated

 

Steve

 

lnguyen
8 - Asteroid

I like this a lot.  It is simple and I could create several tests and put each in a container to turn it off or on accordingly. Thanks

RoelEsselink
8 - Asteroid

Is there any possible way to ensure that the following workflow halts if there is no data coming out of the cross-tab tool at the extreme end?

 

PS : Ticking the option Cancel running workflow on error is not a good idea in this case as this is just a part of a bigger wf and any error on other side would also result in its execution which we don’t ideally want to happen

RoelEsselink_0-1575454074980.png

vbmike73
7 - Meteor

@JordanB Thanks for posting your Stop workflow on error.yxmd workflow. I tried applying the same principals to my flow but it still produced the output file. Then I downloaded your flow and ran it in Alteryx 2021.4 which gave me the same issue. The only thing I changed in your flow was the path of the output, but no matter what, it still creates the output file. I'm trying to understand what exactly is supposed to stop the output from being created. If we are relying on the Runtime setting to stop the flow when it encounters an error, then wouldn't it just be a race to the finish? Since there's nothing to force the Count and Test to finish first, if the output is very small, it will be created before the Count and Test finish. Am I missing something here?

Thabani
5 - Atom

@JordanB 

 

still have the same issue . if there are no records, the output file will still show empty even though the workflow will fail. looks like the test condition is slower than the output.

 

anything im missing