web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / ForAll |Bug |Return fi...
Power Apps
Unanswered

ForAll |Bug |Return first record of output value

(0) ShareShare
ReportReport
Posted on by 107

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)

I have the same question (0)
  • v-yujincui-msft Profile Picture
    on at

    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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard