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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Problem in Inserting a...
Power Apps
Answered

Problem in Inserting a lookup field in an Entity

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi Everebody,

I am new in using PowerApps.

I am developing an app for managing the reservation of the company cars.

For that I have created 2 Entities one with details about the reservation and the second contains Cars Details.

In the first table it is defined a lookup field for relating the 2 entities.

Now when I insert a new reservation from the app, I receive an error message because I evaluate the Lookup Field with a text value.

2020-03-12 18_34_30-Window.png

Could someone Help me?

 

Regards Giorgio

I have the same question (0)
  • Hamish Sheild Profile Picture
    3,005 Most Valuable Professional on at
    Hi @Anonymous,

    Are you able to share the formula that is causing this issue? It will help us give a clearer answer.

    Basically you need to get Power Apps to lookup the entity record that you want in the lookup field and use that in your formula instead of a text value.

    Have you also tried using a form control in the Canvas app that is tied to the parent entity? It sets up all this logic for you. https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/working-with-forms
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi,

    That's the code:

    Collect(CarReservations,
    {CarPlate: G_AvCars.Selected.Value , <---  CarPlate is the Lookup Field the evaluation valu comes from a gallery
    ReservedBy: Lower(User().Email),
    CheckInDT: DateTimeValue(DP_CheckInDT.SelectedDate & " " & CheckInTime.Selected.Hour), <---This Is a Date Picker
    CheckOutDT: DateTimeValue(DP_CheckOutDT.SelectedDate & " " & CheckOutTime.Selected.Hour) <----This Is a Date Picker
    }
    )

    Thanks and regards

     

    Giorgio

  • v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

     

    To patch LookUp field of SharePoint,  you have to patch a record containing '@odata.type', Id and Value from the related list.

    Please try this code:

    Collect(CarReservations,
    {CarPlate:
    {
    '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
    Id: G_AvCars.Selected.ID,
    Value: G_AvCars.Selected.Value
    }
    ,
    ReservedBy: Lower(User().Email),
    CheckInDT: DateTimeValue(DP_CheckInDT.SelectedDate & " " & CheckInTime.Selected.Hour), <---This Is a Date Picker
    CheckOutDT: DateTimeValue(DP_CheckOutDT.SelectedDate & " " & CheckOutTime.Selected.Hour) <----This Is a Date Picker
    }
    )

     Hope this helps.

    Sik

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi Sik,

    thank you for your help.

    Unfortunately the solution you sent me returns an error:

    2020-03-13 11_18_35-Window.png

     

    Just a Think, I don't know if this is a useful information, I'm not using  sharepoint but G_AvCars is a gallery and CarReservations is a CDS entity.

     

    This is how I have applied your solution

    Collect(CarReservations,
    {CarPlate:
    { '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
    Id: G_AvCars.Selected.ID,
    Value: G_AvCars.Selected.Value
    },
    ReservedBy: Lower(User().Email),
    CheckInDT: DateTimeValue(DP_CheckInDT.SelectedDate & " " & CheckInTime.Selected.Hour),
    CheckOutDT: DateTimeValue(DP_CheckOutDT.SelectedDate & " " & CheckOutTime.Selected.Hour)
    }
    )

     

    Regards

     

    Giorgio

     

  • Hamish Sheild Profile Picture
    3,005 Most Valuable Professional on at

    Hi @Anonymous ,

     

    @v-siky-msft suggestion will work for SharePoint but not CDS.

     

    For CDS you need to set the lookup field to the actual record that you want to look up to.  Below I have added a lookup formula in bold which will look up the record based on what was selected in the Gallery.  You will need to adjust the following names to match what you have in your app

    AvCars = the name of the data source for the type of record you are setting in the Lookup field

    AvCar = the field name that represents the CDS unique identifier for the lookup entity

     

    Collect(CarReservations,
    {CarPlate: LookUp(AvCars, AvCar= GUID(G_AvCars.Selected.AvCar)) , <---  CarPlate is the Lookup Field the evaluation valu comes from a gallery
    ReservedBy: Lower(User().Email),
    CheckInDT: DateTimeValue(DP_CheckInDT.SelectedDate & " " & CheckInTime.Selected.Hour), <---This Is a Date Picker
    CheckOutDT: DateTimeValue(DP_CheckOutDT.SelectedDate & " " & CheckOutTime.Selected.Hour) <----This Is a Date Picker
    }
    )

     

    I hope this helps and that you can work it out from here.  It's difficult to give the exact formula without seeing the rest of the app's formulas.

  • v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

     

    Yes, LookUp field is different in SharePoint and CDS.

    @HSheildsolution does make sense for your case, could you please go to have a try?

    Sik

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi HShield,

    I have modified my code as following:

    Collect(CarReservations,
    {CarPlate: LookUp(CarLists, crcd5_carlist = GUID(G_AvCars.Selected.Value)),
    ReservedBy: Lower(User().Email),
    CheckInDT: DateTimeValue(DP_CheckInDT.SelectedDate & " " & CheckInTime.Selected.Hour),
    CheckOutDT: DateTimeValue(DP_CheckOutDT.SelectedDate & " " & CheckOutTime.Selected.Hour)
    }
    )

     

    CarLists is the data source name,

    crcd5_carlist is The name of the Entity, is the unique name across your environment.

     

    Is that what you means?

     

    The formula returns this error:

    Incompatible type. The "CarPlate" field column in the datasource you're updating expects a 'DataEntity' type and you are using  a 'record' type

     

     

    Thanks

     

    Giorgio

  • v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

     

    How do you define the Gallery G_AvCars? What is the Items property?

    The codes should be like this, the LookUp function is to get the entire record from CarLists entity based on selection on G_AvCars

     

    Collect(CarReservations,
    {CarPlate: LookUp(CarLists, crcd5_carlist = GUID(G_AvCars.Selected.crcd5_carlist)),
    ReservedBy: Lower(User().Email),
    CheckInDT: DateTimeValue(DP_CheckInDT.SelectedDate & " " & CheckInTime.Selected.Hour),
    CheckOutDT: DateTimeValue(DP_CheckOutDT.SelectedDate & " " & CheckOutTime.Selected.Hour)
    }
    )

     

    Sik

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi Sik,

    The Item property is 

    Filter(C_AvCar, Value <> "") ----> C_AvCar is a collection.

     

    The gallery is composed by a title and a Icon right, the title contains ThisItem.Value.

    The Icon Right contains the formula: 

    OnSelect=

    Collect(CarReservations,
    {CarPlate: LookUp(CarLists, crcd5_carlist = GUID(G_AvCars.Selected.Value)),
    ReservedBy: Lower(User().Email),
    CheckInDT: DateTimeValue(DP_CheckInDT.SelectedDate & " " & CheckInTime.Selected.Hour),
    CheckOutDT: DateTimeValue(DP_CheckOutDT.SelectedDate & " " & CheckOutTime.Selected.Hour)
    }
    )

  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi guys,

    thank you for your help, I have solved the problem using the patch command as following:

     

    Patch(CarReservations,
    Defaults(CarReservations),
    {CarPlate: LookUp(CarLists, CarPlate = G_AvCars.Selected.Value),
    ReservedBy: Lower(User().Email),
    CheckInDT: DateTimeValue(DP_CheckInDT.SelectedDate & " " & CheckInTime.Selected.Hour),
    CheckOutDT: DateTimeValue(DP_CheckOutDT.SelectedDate & " " & CheckOutTime.Selected.Hour)
    }
    )

     

    Best Regards

     

    Giorgio

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 94

#2
WarrenBelz Profile Picture

WarrenBelz 82 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 38 Super User 2026 Season 1

Last 30 days Overall leaderboard