cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

Value reference issue in ForAll()

Hello,
I have read through many Q&A's and ForAll() documentation but couldn't figure the issue on my own. 

The idea is simple - once button is pressed this ForAll() function updates (using Patch) another table with required records and data:

Set(test1, 2);
ForAll(
    Filter(
        TemplateGalleryList2.AllItems,
        Toggle3.Value = true
    ).ID,
    Notify(
        ID /* prints correct ID */ & test1 & LookUp(
            table_available_tests,
            table_available_tests[@ID] = Value(test1),
            table_available_tests[@Result_1_name]
        )
    );
    Patch( ... );
    )   

As for data source, I filter it so that only toggled options would be patched. Filter gives data in the following form:

data.PNG

Going back to the code above, I used Notify() to debug, and it ideally represents the case occurring in Patch(). 

My issue - trying to reference the current ID number that is represented by the row that ForAll() is currently looping through. The Notify() function successfully prints this value by just using ID (which is 4 and 8). In the meanwhile if I input ID in the LookUp() function instead of test1, it fails to lookup a required value in the other table! (looking down from the output values it seems that ID = 1)
On the other hand if a temporary variable test1 is used the lookup is performed as expected.

 

I played around using Value() and disambiguation operator but couldn't find a cause.

 

Thanks for help!

1 ACCEPTED SOLUTION

Accepted Solutions
Super User II
Super User II

Hi @DrMantas ,

I propose to use a diffferent  approach, for this:

ForAll(
      Filter(
             TemplateGalleryList2.AllItems,Toggle3.Value = true).ID,
             Notify(
                             ID /* prints correct ID */ & test1 &

                             LookUp(
                                   RenameColumns(table_available_tests,"ID","table_available_tests_ID"),
                                   table_available_tests_ID = ID,
                                   Result_1_name
                              )
               );
              Patch( ... );
)

 

Hope it helps !

 

View solution in original post

6 REPLIES 6
Super User II
Super User II

Hi @DrMantas ,

I propose to use a diffferent  approach, for this:

ForAll(
      Filter(
             TemplateGalleryList2.AllItems,Toggle3.Value = true).ID,
             Notify(
                             ID /* prints correct ID */ & test1 &

                             LookUp(
                                   RenameColumns(table_available_tests,"ID","table_available_tests_ID"),
                                   table_available_tests_ID = ID,
                                   Result_1_name
                              )
               );
              Patch( ... );
)

 

Hope it helps !

 

View solution in original post

Frequent Visitor

Thanks, @gabibalaban, this worked very nicely!

And although I will keep it this way for now, I think that this is more of a workaround to an existing referencing problem. Wouldn't your way be detrimental performance wise, as a new instance of table is 'created' and a column renamed, just to perform search?

 

As per usual database naming rules, data fields of the same type in different tables should be named the same (for example Address vs CustomerAddress). This is what I tried to follow keeping the ID column names the same, as IDs there are the same (test IDs). Doesn't column renaming undermine this convention?

I know... It’s frustrating isn’t it, this referencing problem ?

Don’t worry about performance issue of the app applying this workaround, because this instance of the out table is kept only for this ForAll usage and it is not “allocated” to a global or context variable.

If my solution satisfied your current need please don’t forget to mark as solution.

Thank you !

Frequent Visitor

Hi, @gabibalaban 

I have been trying to use RenameColumns() in other ForAll() functions, unfortunately faced an error with RenameColumns() not recognizing a column name...
The code is as follows:

 

ForAll(
    TemplateGalleryList3_2.AllItems,
    Patch(
        list_of_all_tests,
        LookUp(
            RenameColumns(
            list_of_all_tests,
            "test id", /* doesnt recognise, although it exists */
            "list_of_all_tests_test_id", 
            "test project id", /* doesnt recognise, although it exists */
            "list_of_all_tests_test_project_id"
            ),
            list_of_all_tests_test_project_id = LoadProjectID && list_of_all_tests_test_id = 'test id'
            ),
            {
                Result_1_value: TextInput2.Text,
                Result_2_value: TextInput2_1.Text
            }
    )
);

 

The error I get - "The specified column 'test id' does not exist". If I change "test id" to the name of other existing column, and repeat this for another column that is supposed to be changed, then I get an error that newly renamed columns doesn't exist, when trying to use them in the LookUp() as you can see above.

I am 100% sure that columns that I am trying to rename do exist in the table of interest.


Any thoughts why this might happen?

Hi @DrMantas ,

 

@RandyHayes ,gives you an answer on this matter, isn't he ?

His solution is the best solution I ever think and I have to bow in front of the master.

Frequent Visitor

Hi @gabibalaban , yes his solution using As worked very well, but it is definitely worth knowing both methods, yours worked in most cases too!

Helpful resources

Announcements
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (11,214)