Switch() requires not null input

I have two variables - one of which will always be null, but it could be either. Variable A is not base64 encoded and needs to be before it is sent in a POST. Variable B already arrives base64 encoded. When I add an ifEmpty or switch and wrap Variable A in base64() I get an error when the scenario triggers with a null value for Variable A. Shouldn’t base64() just silently return nothing and let the scenario continue? It seems to have a required not null input that causes that run to error out but the other iterations to complete.

Hi! If I understand correctly, it seems like the issue is that you want the scenario to continue even when processing a variable that might be null or empty, without causing it to stop.

Here’s how you can set it up so that Variable A is skipped if it’s empty or null, but still processed through base64() if it contains data:

Simple version:

{{if(empty($1.value); ""; base64($1.value))}}
  • If the variable is empty, an empty string is returned.
  • If the variable contains data, it is encoded using base64().

To handle null:

{{if(or(empty($1.value); not($1.value)); ""; base64($1.value))}}
  • We check if the variable is empty or null. If either of these conditions is met, an empty string is returned.
  • If the variable contains data, base64() is applied.

This will allow the scenario to continue running, even if Variable A is empty or null, avoiding errors and not stopping the process.

If the variable is empty or null: an empty string ("") is passed.

If the variable contains data: the result of the base64() function is passed.

:thinking:

That’s what I would expect, but this is what I’m getting:

image

I assume this is somehow related to the other topic you opened? Can’t use variable in SWITCH output?

I missed seeing your first message, which caused me to look back over my code and I realized the error is because the first argument in my switch statement is evaluating as null, which is expected in this case.

My first case looks for a not null value, the second for a null value. On second review, I’m not sure I can use !=null in the first evaluation, but that also doesn’t seem to be the issue since it is stating the first value (presumably what I am evaluating the value of - in this case null) is null: switch(null;!=null;A;null;B)

They are both being used in the same scenario, but in different parts.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.