How To Create A If/Else When A Page Variable Is "empty"?


#1

I have three variables (A,B,C) coming into my page.

I need to somehow set up the following:

  1. If A is empty set value to B
  2. If A + B are empty, set value to C

Must be in that order above.

Is there a way to do this some how?


#2

If your variables, A, B and C, are strings then to check empty choose Static Inputs and String and leave the Input value blank.

If you want to check if A+B is empty (assuming + here means join the two strings together) there are different ways.

  1. Use If/Else. That is check if A is empty, then in the true branch check if B is also empty.
  2. Use the Append so string action to join A and B and simply check if the result is empty with a single if/else action.
  3. Use the new Build a string action to join A and B and check if the result is empty with a single if/else action.

Personally i will use the 2nd approach.

In terms of the order i think there is an issue with your logic.
A+B is empty logically implies A is empty.
This is because the only way for A+B to be empty is that both A and B are empty.
Since the first condition doesn’t depend on B it means the first condition will always hold if A is empty irrespective of the value of B.
This means that even if A is empty and B is empty the first condition will still hold and set the value to B.
Then the second condition will also hold and overwrite the value to C.
So think through your logic and correct it.


#3

Thanks again @seanhoots for jumping in.

I tried this, When Page Variable A is empty, set value to Page Variable B, but still doesn’t want to work for me.

Does it work with page variables?

Secondly, what about using similar function in a list/list tile which is dynamic? I can’t set the value on a dynamic element as it must come from the response. How do I re-bind a response to the same element if something isn’t contained in the response?


#4

Yes it should work with page variables or any variable even values from response.
If it’s not working U’re definitely doing something wrong which I obviously I can’t tell from here.
You can debug by trying to write the values to text fields to see if they contain the values you expect.
You can also call a dialog in the true case of the if/else to ensure that it executes.
If it doesn’t then A isn’t empty


#5

Is there a way to view the variables in the app?

I’m not sure why it’s not ‘seeing’ that the variable is indeed blank… it’s setting it to a blank field/element as well.

I’ve debugged it by adding in the B and C page variables which show as ‘test’ and ‘3E0’ in blue font in the image below:

image

It’s supposed to SWAP variable A for B (test) and format like this:

image

My if/else is formatted correctly as well to show variable B if A is empty:

image

IF TRUE:

image

If the original page variable is blank - does it always set the value it to blank on-create?

Shouldn’t it default to the default text of the element like other areas of the app?


#6

Try the opposite.
Instead of testing for if A is empty, test for if A is not empty and reverse your true and false actions


#7

I like @seanhoots suggesting.

To answer the other part of the question… You can print values out in Dropsource by dropping in a label or textfield element and doing a Set Value to print out values into it. When you no longer need it for troubleshooting, you can delete it.


#8

What @seanhoots suggested worked where I flip the order :slight_smile:

but what about using a similar function in a list/list tile which is dynamic?

I can’t set the value on a dynamic element as it must come from the response.

How do I re-bind a response to the same element, if something isn’t contained in the response?


#9

How is it possible to set an “order” or a precedent of which gets displayed first vs. last?

“A” (primary) should move to “B” (secondary) and if A+B are empty, revert to “C” (tertiary)

  1. Right now I have “A” created and set on creation of the page.

  2. Then if A is = “1” (which it could never in my case…) I set it to value B in my false statement (reverse logic works, ‘empty’ does not)

  3. The trouble comes when “A” and “B” are empty - using a reverse logic if/else as described above (because for some reason it doesn’t trigger when it’s indeed ‘empty’ for me) isn’t possible from my understanding.

And another issue is that all 3 variables (A/B/C) may be present, so how would I set it to A as the default with B, C to fall back on? The order of operations is where I’m stuck. :frowning:


#10

Looks like the best way (possibly the only way I can see) is to modify the back end…

Thanks @seanhoots and @wade


#11

It might be the better way if the if/else logic is becoming convoluted here with all the variables in play. Especially if any of them are dynamic in nature as well.