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.

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
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (3,571)