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

Lookup Field not Saving - Part II

I have a table in CDS that I'm building a Power App form to insert into. One of the fields is a Lookup combo box pulling data from another CDS table. Initially everything worked fine on the form, but when I click submit, this field does not save. I did some research and found posts that appeared to address the issue:

 

Lookup Field not Saving 

 

The recommended solution is to add the following text to the update field:

 

If(

   !IsBlank("ProductionPlantValue5),

   (

      {

         '@odata.type': "Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",

         Id:"ProductionPlantValue5.Selected.ID,

         Value: "ProductionPlantValue5.Selected.Production_x0020_Plant1

      }

   )

)

 

My values are as follows:

 

Control Name: DataCardValue13

Column Value to Reference Display Name: Name

Column Value to Reference Data Field Name: cr5ed_name

 

If(
!IsBlank(DataCardValue13),
(
{
'@odata.type': "Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
Id:DataCardValue13.Selected.cr5ed_id,
Value: DataCardValue13.Selected.cr5ed_name
}
)

)

 

All variations of this statement throw an error and no record is created at all. I am not sure what to put in place of the "ID" listed in the Id line of the snippet above. The table I am referencing was loaded from excel, so the unique identifier column appears not to have been populated and has only blank values. I created a separate unique key and referenced that (cr5ed_id) but that is not working either. 

 

 @WarrenBelz helped answer the original post by @Bartron . Any insight you guys can offer would be highly appreciated! Thanks! 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tim_RA
Regular Visitor

Thanks Everyone!

 

I received a response from @WarrenBelz which solved the issue, so I will re-post here in case it helps others. There was no reason for me to use the lookup datatype and it was causing unnecessary complexity and headache.

 

----

 

Hi Tim,

The first thing you need to ask yourself is why are you using Lookup fields with Power Apps. You can do exactly the same lookup in Power Apps and write back to a Text field. I have a blog on data structure:

https://www.practicalpowerapps.com/data/constructing-your-first-power-app-before-you-start/

that may assist.

 

Putting this aside, the pain you can cause for yourself comes from the fact that the field has two elements, neither of which belong to the list you are writing to. The Value is easy enough as you have selected this, but the Id is the ID (note case on both of these) of the item in the other list you are looking up, so unless you simply "leave alone" the control that Power Apps will build, you have to retrieve the Id from the other list. My example posted was when you have used the other list as the Items of a combo box (so both values will be there).

View solution in original post

2 REPLIES 2
EricRegnier
Super User
Super User

Hi @Tim_RA,

The sample code references SharePoint, but you are using Dataverse (formally CDS) right? To update a lookup you can simply refence the selected object and don't need to reference the exact physical column name. So far example:

Patch(TableA, Defaults(TableA), {LookupColumn: DataCardValue13.Selected})

instead of

Patch(TableA, Defaults(TableA), {LookupColumn: DataCardValue13.Selected.cr5ed_id})

 Hope this helps!

Tim_RA
Regular Visitor

Thanks Everyone!

 

I received a response from @WarrenBelz which solved the issue, so I will re-post here in case it helps others. There was no reason for me to use the lookup datatype and it was causing unnecessary complexity and headache.

 

----

 

Hi Tim,

The first thing you need to ask yourself is why are you using Lookup fields with Power Apps. You can do exactly the same lookup in Power Apps and write back to a Text field. I have a blog on data structure:

https://www.practicalpowerapps.com/data/constructing-your-first-power-app-before-you-start/

that may assist.

 

Putting this aside, the pain you can cause for yourself comes from the fact that the field has two elements, neither of which belong to the list you are writing to. The Value is easy enough as you have selected this, but the Id is the ID (note case on both of these) of the item in the other list you are looking up, so unless you simply "leave alone" the control that Power Apps will build, you have to retrieve the Id from the other list. My example posted was when you have used the other list as the Items of a combo box (so both values will be there).

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Users online (1,693)