Looping, Iteration?

I have a variable length field of data that needs to be validated.

Is there any way to iterate over data? For example, is there some sort of for loop, doโ€ฆuntil, etc? If no, as I suspect, how could you handle scenario below?

Example Psuedo Code, step 3 is either a or b, not both:

  1. Data entered by user, triggers workflow action
  2. Workflow action copies Data to a hidden or virtual column so it can be worked upon
    3a) Action iterates through each character, word, whatever and checks on each individually, updating the hidden column as necessary if data needed to be changed
    3b) Action iterates through data and finds non conformant data, rejects the update
  3. Action copies modified data from hidden column back to original cell, or rejects update as determined in step3.

TIA for any assistance you may be able to provide.

erik

Solved Solved
0 20 2,214
1 ACCEPTED SOLUTION

Oh yeah, youโ€™re talking about nesting. All day.

If(true=false, 
  "Wait...what?!?!", 
switch([Some_Column], 
  "1", "first option", 
  "2", "second", 
if("nothing"="something", 
  "wow!!!!", 
"the end")))

As long as you keep track of where youโ€™re at in the arguments of whatever expression youโ€™re on, and close all the parenthesis, you can stack things so theyโ€™re crazyโ€ฆ


But for what youโ€™re wanting to do, since youโ€™ll ALWAYS want these characters to be removed - I wouldnโ€™t bother with the condition, just nest the substitutes.

View solution in original post

20 REPLIES 20

Thereโ€™s no looping like that, something like a FOR() statement???

But you can do bulk actions, and you can create an action that would take your list of records and run your validation action over them.

First create an individual action for each of your validation steps.
Next, put those actions in a Group action in the order you wish them to process.
Finally, create the โ€œexecute an action on a set of rowsโ€ action that calls your grouped action.

I guess in a way, the โ€œData: execute an action on a set of rowsโ€ is kinda like a FOR() statementโ€ฆ

FOR each of the rows, do THIS action.

Well, if I have a text field, I donโ€™t know how long the string it contains is when building the action. Say a user enters 5 characters - the action will need to evaluate 5 times, once for each character. Next time I might need to check on 25 characters. How would I setup an action that can apply a test to any given number of characters/words without some sort of looping construct?

I cannot think of a way that would allow you to do this. I would suggest to look for a way to design the data differently.

I agree with @Bahbus, you wonโ€™t be able to do something like that.

Perhaps if you gave us some clues as to what youโ€™re trying to do, Iโ€™m sure someone here will have some ideas.

Not sure if this helps, but did you consider to use Contains() expression?

Thanks @Steve. These two posts are related, as you surmised. Thanks @MultiTech_Visions as well for a solution (other thread) that pointed me in the right direction.

Follow up question: Is there a way to use an IF() construct in such a way that multiple actions are assigned to the true and false events? Example:

IF( some expression,
true do something AND do something AND do something,
false do other thing AND another thing
)

Are the expressions used for true and false limited to a single action?

Think of it more like โ€œthe space in the formulaโ€ needs either True or False - meaning, the place you enter the conditions in the formula - however you get there is up to you.

IF( true
IF( true = true
IF( and(true = true, false = false)

all equal true

You can have as many conditions inside the condition space, as long as it ultimately results in either true or false.

@MultiTech_Visions I understand about setting multiple conditions using AND, OR, etc. What I am asking about is the โ€œthen doโ€ and โ€œelse doโ€ parts.

More detailed example:

< conditional >
IF(
OR(
contains([MAC Address Entry], โ€œgโ€),
contains([MAC Address Entry], โ€œhโ€),
contains([MAC Address Entry], โ€œiโ€) ),
โ€ฆ

< then do >
(SUBSTITUTE([MAC Address Entry], โ€œgโ€, โ€œโ€))
(SUBSTITUTE([MAC Address Entry], โ€œhโ€, โ€œโ€))
(SUBSTITUTE([MAC Address Entry], โ€œiโ€, โ€œโ€)),
โ€ฆ

< else do >
SOMETHING ELSE
SOMETHING ELSE

I hope that makes the question a bit clearer. Thanks again for imparting your knowledge on us noobs!

I have tried the following in the formula for a field, but it always hits the first one (g) and skips the second (h). So now Iโ€™m trying to see if I can stack actions in the < then do > section of the expression.

< only first condition happens >
IF(
contains([MAC Address Entry], โ€œgโ€),
(SUBSTITUTE([MAC Address Entry], โ€œgโ€), โ€œโ€),
([MAC Address Entry])
)

IF(
contains([MAC Address Entry], โ€œhโ€),
(SUBSTITUTE([MAC Address Entry], โ€œhโ€), โ€œโ€),
([MAC Address Entry])
)

Oh yeah, youโ€™re talking about nesting. All day.

If(true=false, 
  "Wait...what?!?!", 
switch([Some_Column], 
  "1", "first option", 
  "2", "second", 
if("nothing"="something", 
  "wow!!!!", 
"the end")))

As long as you keep track of where youโ€™re at in the arguments of whatever expression youโ€™re on, and close all the parenthesis, you can stack things so theyโ€™re crazyโ€ฆ


But for what youโ€™re wanting to do, since youโ€™ll ALWAYS want these characters to be removed - I wouldnโ€™t bother with the condition, just nest the substitutes.

@MultiTech_Visions you rock! Itโ€™s gonna be ugly, but at least I know how to do it now.

Another follow up: is there a way to add comments into a long expression like that? # or // or something tells interpreter to ignore line?

No, unfortunately. We asked for it awhile ago, but due to how things are parsed (especially with workflows and templates) thereโ€™s a limitation to that.

Also, when using a literal double quote, open/close parenthesis, etc is there a way or need to escape certain characters?

SUBSTITUTE([MAC Address Entry], โ€œ< double quote >โ€, โ€œโ€)

should it be like this: SUBSTITUTE([MAC Address Entry], โ€œโ€", โ€œโ€)

or like this: SUBSTITUTE([MAC Address Entry], " \ " ", โ€œโ€) ignoring extra spaces

As long as things are contained inside the double quotes, you can enter any string you wish - even single quotes for apostrophes.
So:

โ€œCanโ€™t figure it outโ€ = Canโ€™t figure it out

AppSheet is smart about things like that.

You canโ€™t include double quotes inside your double-quoted-text though, for that you can use single quotes:

'Then she said, โ€œSomething wild!!!โ€ โ€™ = Then she said, โ€œSomething wild!!!โ€

OK, it is so close now.

I have found one seeming exception to the smart double quotes: single quote. I have not been able to find a way to test against a single quote

IF(
ISNOTBLANK([MAC Address Entry]),
SUBSTITUTE([MAC Address Entry], " โ€™ ", โ€œโ€), โ€œblankโ€) < extra spaces added for clarity >

This does not work. Insert anything other than a single quote inside the SUBSTITUTE line and it works great. Do you know of a way to check against a single quote, or is this possibly a bug?

Edit: I have tried to following patterns for single quote, all of which failed:

< extra spaces added for clarity >
" โ€™ "
โ€™ โ€™ โ€™
โ€™ " โ€™ " โ€™ < interprets but does function as intended >
" \ โ€™ "

Canโ€™t be done. Itโ€™s a known limitation of the parser library. (Last I brought the issue up.)

Thatโ€™s a bummer. Seems to me that, for a data entry/capture application platform, itโ€™s fairly important to be able to test against any possible character input on a keyboard (or read from OCR, Scanner, etc). Do you know if there is a plan to overcome this limitation?

Iโ€™m sure itโ€™s one of many to-doโ€™s on their ever-growing list, but I imagine will only be part of a larger overall upgrade or overhaul.

I do not know.

Top Labels in this Space