Conditional execute

i have a list which maybe empty so is there a way to conditional execute the next node? and how to use If node?

Use a List.FilterByBoolMask node. Connect it to your elemts coming in and the bool from the IsEmpty node. That will give you two lists out. One of Elements and then other of empty lists. Then you can do what you want with them after that.

thanks Sean1, but i don’t think it’s working, if the original list is empty then both output of FilterBoolMask are empty, List.LastItem node will generate warning no matter what.
my questions:

  1. how to “not connect” to next node if certain condition i.e. empty list
  2. how to use If node, i don’t understand that “simple” node yet

Would you share a complete image of your graph? If the Entire list is empty, what are you trying to get with “List.LastItem”?

Ty something like this. There will be a warning, but the node should run as inteded either way.

You may want to check if the Elements.Delete works with empty lists.

Try this, it shouldn’t throw and error if the list is empty.


Really nice @SeanP !

Didn’t knew that List.Map could avoid those kind of situations :slight_smile:

1 Like

You can also use scope if node for this - but it’s a bit tricky - the two input branches cannot share any nodes or data.

Wouldn’t the condition being defined by one of the branches (the case here) create a circular dependancy ?

have to create two independent copies of the same list - scopeIf only matters if you want to avoid executing one of the branches.

If you only care about the data passed through - then the if should work -

you can also use a ternary operator ? or if statement inside an imperative block.

1 Like

can anyone explain how to use If node and ScopeIf node? sounds simple enough but i don’t get it yet

Nesting the if statement in an in-line function that does nothing can also prevent the error.

It seems you are the ScopeIf expert here, so I wonder if you might help me with trying to wrap my head around how to implement this in my definition.

I have a script which is updating elements based on excel-data. If it can match data, it will execute one branch of the script; if it cannot match data it will place new elements.

As is often the case, all of the data can find a match, and one branch receives an empty list.

Here is where the empty-list shows up, and where i would like to stop the nodes from executing when receiving an empty list:

I am simply trying to get ride of “meaningless” errors when an empty list is sent to a node. It sounds like ScopeIf can help here, but I have no idea how I go about using it.

Fucction.Create and Function.Apply would suppress the warnings and likely keep things neater over time.

I am sure that your response gets me to where I need to go…unfortunately, I don’t comprehend it.

When it comes to string basic nodes together, I can accomplish what I need to. When it comes to using more “advanced” nodes like “function.compose” and “apply” I am afraid that I am a novice.