I have written a component function to extract a token from a string (eg. tokens stored as k1:v1|k2:v2|... and wish to return the value (eg. v2) from a token (eg. k2).
If I attempt to do so using ForAll in a single pass it returns blank, but if I take the single column table output from the ForAll and extract the result it all works fine.
There is no sync issue, all variables initialised well ahead of time (vDebugTokens=HC:111|FL:222|efw:333|ac:444 and vDebugTokenToFind=efw).
[As an aside, this wouldnt be necessary if JSON read/write for records WITHIN powerapps without resorting to flow was implemented]
//////////////////////////////////////
////Extract to a single column table and then extract result from that collection- WORKS
/////////////////////////////////////////////////
ClearCollect(vDebugTokenPairMatches,
//So split into each key:value
ForAll(Split(vDebugTokens,"|") As KVpairs,
//then if keyX: found
If(StartsWith(Trim(KVpairs.Result), Trim(vDebugTokenToFind & ":")),
//then split that key:value result at the : gives two records-- the last record should be the value
Last(Split(KVpairs.Result,":"))
) //If
) //forAll
); //Collect
Set(vDebugTokenValueTwoFunctions,Trim(First(vDebugTokenPairMatches).Result));
//////////////////////////////////////
/////Extract result from single column table- FAILS
//////////////////////////////////////
Set(vDebugTokenValueOneFunction,
Trim(
First(
//So split into each key:value
ForAll(Split(vDebugTokens,"|") As KVpairs,
//then if keyX: found
If(StartsWith(Trim(KVpairs.Result), Trim(vDebugTokenToFind & ":")),
//then split that key:value result at the : gives two records-- the last record should be the value
Last(Split(KVpairs.Result,":"))
) //If
) //forAll
).Result //First- First found match and return its value
) //Trim the value
); //Set
Reset(TextInput3);Reset(TextInput3_1)
Hi @PeterCBell_au,
Do you want to return the corresponding value based on the input of Token, and consider the impact of spaces.
I have made a test for your reference.
1. Add a Text Input1 Control and set its Default property to vDebugTokens (variable name)
2. Add a Text Input2 Control for entering Token.
3. Add a Text Input4 Control to display the value corresponding to Token and set its Default property to vDebugTokenValueTwoFunctions.
4. Add an Icon Control and apply the following formula on its property as:
//Initializing variables and clearing collection
Set(vDebugTokens," HC: 111| FL: 222|efw:333|ac :444");
Set(vDebugTokenToFind,TextInput2.Text);
Clear(vDebugTokenPairMatches);
//Create a collection with two columns to store the Token and the corresponding value respectively
ForAll(
Split(vDebugTokens,"|"),
Collect(vDebugTokenPairMatches,
{
title: First(Split(Result,":").Result),
number: Last(Split(Result,":").Result)
})
);
//Set the variable to display the value corresponding to the Token
Set(vDebugTokenValueTwoFunctions,
Trim(LookUp(vDebugTokenPairMatches,Trim(title.Result) = Trim(vDebugTokenToFind)).number.Result)
);
Result Screenshots:
Best Regards,
Charlie Choi
WarrenBelz
109
Most Valuable Professional
Michael E. Gernaey
72
Super User 2025 Season 1
mmbr1606
71
Super User 2025 Season 1