cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
cholopa
Helper II
Helper II

For all, patch and Lookup

HI:

 

I'm tring to automaticly create new records on a sharepoint list(list_a), base on the quantity and values of a filter gallery(Gallery4).

 

This next example works fine, creating the records I want each one with the one of the values(value_1) of the Gallery4

 

ForAll(
Gallery4.AllItems;
Patch(
'list_a';
Defaults('list_a');
{value_1=Subtitle3.Text)}
)
)

 

Now I want to substitude value_1 with a lookup value(lu_value) to another list, si I have tried something like this:

 

ForAll(
Gallery4.AllItems;
Patch(
'list_a';
Defaults('list_a');
{lu_value=Subtitle3.Text)}
)
)

 

With htis, I get an error saing the lu_value is expecting a record and is getting a number, so i have tried this:

 

ForAll(
Gallery4.AllItems;
Patch(
'list_a';
Defaults('list_a');
{lu_value=Lookup('list_b'; ID=Subtitle3.Text)}
)
)

 

With this I get an error, saying that lu_value is expecting another kind of record, though lu_value is a lookup field to "list_b".....

 

Any clue how to solve this?

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @cholopa ,

A Lookup field is actually a Table consisting of the ID of the record chosen in the "other" list and the value in the nominated field that record. To Patch to a Lookup field, you need both of those values.

Currently it seems you have a free-form Text field, so for a start unless the value put in there exactly matches one of the values in the Lookup column, you will not be able to Patch it. If it does match, the syntax would be

ForAll(
   Gallery4.AllItems;
   Patch(
      'list_a';
      Defaults('list_a');
      {
         lu_value:
         {
            Value:Subtitle3.Text;
            Id:
            Lookup(
               'list_b'; 
                FieldName=Subtitle3.Text
            ).ID
         }
      }
   )
)

FieldName is the field in list_b being looked up.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

3 REPLIES 3
cholopa
Helper II
Helper II

Notice in our country we use ";" instead of ","

WarrenBelz
Super User
Super User

Hi @cholopa ,

A Lookup field is actually a Table consisting of the ID of the record chosen in the "other" list and the value in the nominated field that record. To Patch to a Lookup field, you need both of those values.

Currently it seems you have a free-form Text field, so for a start unless the value put in there exactly matches one of the values in the Lookup column, you will not be able to Patch it. If it does match, the syntax would be

ForAll(
   Gallery4.AllItems;
   Patch(
      'list_a';
      Defaults('list_a');
      {
         lu_value:
         {
            Value:Subtitle3.Text;
            Id:
            Lookup(
               'list_b'; 
                FieldName=Subtitle3.Text
            ).ID
         }
      }
   )
)

FieldName is the field in list_b being looked up.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

cholopa
Helper II
Helper II

Hi:

 

Work fine!!!

Thanks very much!!!!

 

Just a notice, I had to also add value to Subtitle.Text for it to work properly (to change a text for a number)

 

Here is the final code(remember ";" is subsitute by "," in my country.:

 

ForAll(
    Gallery4.AllItems;
    Patch(
        'Mnto equipos basicos';
        Defaults('Mnto equipos basicos');
        {
        LU_equipo:
        {
            Value:LookUp(Equipos;ID=Value(Subtitle3.Text)).codigo_x0020_cliente;
            Id:LookUp(Equipos;ID=Value(Subtitle3.Text)).ID  
        }
        }
    )
)



 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,524)