List wrongly separated by using string_split
Question
Application Type
Reactive

Hi community,

I have a input parameter called ListString (variable of type Text) that contains list items as string, separated by a separator. I also have a input parameter called ListItem (variable of type text) that contains a list item to insert or delete (see flow below).

When the ListString is empty the outcome is ;45 but should be 45. As you can see in de debugger screenshot below a list with 2 items in it is returned from the string split (String_Split is used from Text extension) I use in my flow. I am not sure why this empty record is inserted, because this caused the list to be ;45. I think the string split function does see "" as a record and it tries to split it, but I am not sure on how to solve this issue. Does anybody know how to fix this?

Best,

Bart

mvp_badge
MVP
Solution

Hi Bart,

Indeed the string_split working is a bit odd. Still, you can conditionally change the flow by defining a conditional IF check at the start of the action flow and get the expected output.

Conditional Check:

Trim(ListString) <> ""

See the attached oml file

I hope this helps you!


Kind regards,

Benjith Sam

InsertDeleteListItemListString.oml

You are right. The String_Split on an empty string results in one Text record with an empty value, so appending the new value results in 2 records.

But other than that, why don't you just use text operator on your string?
If you use Index(";" + ListString + ";", ";" + ListItem + ";"), you can tell if the ListItem is already in the ListString. If not, just add it --> ListString = ListString + ";" + ListItem.
Removing can also be done with a Replace(";" + ListString + ";", ";" + ListItem + ";",";")

Hi Lennart,

Thanks for your reply. Good to know I was seeing it correctly. I am not sure If I am understanding you correctly. Is it possible to let me see what you are trying to do? I did attach a .oml with this part separated from the rest of the application

Best,

Bart


InsertDeleteListItemListString.oml

mvp_badge
MVP
Solution

Hi Bart,

Indeed the string_split working is a bit odd. Still, you can conditionally change the flow by defining a conditional IF check at the start of the action flow and get the expected output.

Conditional Check:

Trim(ListString) <> ""

See the attached oml file

I hope this helps you!


Kind regards,

Benjith Sam

InsertDeleteListItemListString.oml

Hi Benjith,

Thanks for your reply! I will mark your answer as the solution since this solves my problem. I also came up with an alternative myself by changing the last assign in the flow: 

If(Index(String_Join.Text, ";") = 0, Substr(String_Join.Text, 1, Length(String_Join.Text) - 1), String_Join.Text)

This also solves the problem, but it in my opinion your solution is better, because you solve the problem in the beginning and not at the end.

Best,

Bart

mvp_badge
MVP

Sure thing, the advantage of defining a conditional check initially is avoiding unnecessary code execution.

Glad to help you!


Kind regards,

Benjith Sam

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.