Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Unanswered

ForAll |Bug |Return first record of output value

(0) ShareShare
ReportReport
Posted on by 105

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]

Screenshot 2021-12-31 111609.jpg

//////////////////////////////////////

////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)

  • v-yujincui-msft Profile Picture
    on at
    Re: ForAll |Bug |Return first record of output value

    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:

    vyujincuimsft_0-1641372694090.png

     

    vyujincuimsft_1-1641372694096.png

     

    Best Regards,

    Charlie Choi

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Leaderboard > Power Apps - Power Apps Pro Dev & ISV

#1
WarrenBelz Profile Picture

WarrenBelz 109 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 72 Super User 2025 Season 1

#3
mmbr1606 Profile Picture

mmbr1606 71 Super User 2025 Season 1

Overall leaderboard