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 / Set Lookup Field Value...
Power Apps
Unanswered

Set Lookup Field Value from PCF

(0) ShareShare
ReportReport
Posted on by 172

Hi Everyone,

 

I hope I have posted this in the correct place and hopefully this will be a simple thing for most. I am *very* new to PCF development (there is nobody else in our company to do it) and I'm looking to use a component to solve our addressing issues (seems to be a common theme too). I have used another component from the PCF Gallery to get the addressing details, but now I need to set the value of a couple of lookups (State and Country) to the values returned from the API. 

 

I've seen a lot of posts about creating custom lookup components, but I can't seem to find anything that relates to this slightly simpler task (or it seems simpler). Can anyone point me at any resources that might help me walk through this?

 

Thanks!

I have the same question (0)
  • Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at

    Hi @Serviced2000 , 

     

    You can have a look to the Lookup PCF example: https://docs.microsoft.com/en-us/powerapps/developer/component-framework/sample-controls/lookup-control?WT.mc_id=BA-MVP-5004107. There is a link to the source code.

     

    If you have a more specific question, please let us know.

     

    Hope this helps!

     

    Kind regards,

    Diana

  • cchannon Profile Picture
    4,702 Moderator on at

    OK, to set a Lookup Value from a PCF (assuming your PCF isn't Bound to that lookup) you will need to use the WebApi in your PCF. First, uncomment the use of WebApi from the manifest file and rebuild your control. This will give you a context.webapi object in typescript you can use to perform various actions.

     

    Next, you will need to put an update in the correct place in your code. Here is a reference page on the PCF webapi update syntax, but it doesn't have any examples, so check out the the client script api reference page for examples (the syntax is basically identical).

     

    What you'll see is that when updating a lookup value you need to use this odata syntax to bind the guid input you're providing to a specific table.

    var data =
     {
     "primarycontactid@odata.bind": "/contacts(61a0e5b9-88df-e311-b8e5-6c3be5a8b200)"
     }

    So your data object will contain a row that references:

    "{fieldname of your lookup}@odata.bind" :  "/{plural form of the lookup table name}({record guid})"

  • Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at

    Hi @cchannon , Hi @Serviced2000 

     

    When I think to an address-autocomplete, usually I have a service which retrieves the data. Usually strings. 

    An adress-autocomplete can be bound to several properties like street, city. There we can add the lookup bound properties country and state too.
    After the service returns the suggestions, and one of them is chosen, I would add the webAPI request in order to get the corresponding lookups, and set it together with the other propeties through getOutputs.

    This way, the data is consistent: the user saves all address-fields or nothing.

     

    Kind regards,

    Diana

     

     

  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    Also, you can use my toolkit that already contains autocomplete that supports lookup fields for country/state - https://github.com/AndrewButenko/ABControlsToolkit

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I just need the value of a lookup.

     

    How can I just get the lookup entity reference as value?

     

     

     <property name="LookupProperty" display-name-key="Lookup" description-key="Lookup" of-type="Lookup.Simple" usage="bound" required="true" />

     

     Setting the property usage to "input" or "bound" lets me choose it in the form editor for the pcf control but then the pcf is not working anymore and removing the selected lookup from the component options isn't possible. The pcf is not showing as component anymore.

    Features like utility and webapi are already enabled.

  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    Can you please provide your full manifest file?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at
    <?xml version="1.0" encoding="utf-8" ?>
    <manifest>
     <control namespace="tvd" constructor="Griddy" version="0.0.5" display-name-key="Griddy" description-key="Griddy description" control-type="standard">
     <data-set name="griddy" display-name-key="griddy subgrid" cds-data-set-options="displayCommandBar:true;displayViewSelector:true;displayQuickFindSearch:true">
     </data-set>
     <property name="somePhase" display-name-key="Some phase" description-key="Some phase" of-type="OptionSet" usage="input" required="true" />
     <property name="Lookup" display-name-key="Lookup" description-key="Lookup" of-type="Lookup.Simple" usage="bound" required="true" />
     <resources>
     <css path="css/Griddy.css" order="1" />
     <code path="index.ts" order="2"/>
     <resx path="strings/Griddy.1033.resx" version="1.0.0" />
     </resources>
     <feature-usage>
     <uses-feature name="Utility" required="true" />
     <uses-feature name="WebAPI" required="true" />
     </feature-usage>
     </control>
    </manifest>
  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    It seems that your PCF control is of "Dataset" type. How do you plan to use that lookup and what do you plan to bind it to?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I plan to bind a custom entity lookup to it so I can read out the value in pcf for filtering the dataset. I want to avoid having a dummy field just to fill the guid of the lookup and listen to this dummy control.

  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    I'm afraid it won't work that way. You will have to create a PCF control of "Field" type and figure out how to work with the Grid.

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!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 846

#2
Valantis Profile Picture

Valantis 532

#3
Haque Profile Picture

Haque 410

Last 30 days Overall leaderboard