How to set a lookup value in Power Apps Portals

| Yahya Ahmed

Problem statement: I have the unique identifier’s(GUIDs) of the Contact and Customer tables respectively which in this case are stored in my session local storage and I would like to populate the Contact and Customer’s lookup fields in the Opportunity table creation Form using those GUID values.

Power Apps portal lookup

Things your need to do before you start working on portal Web APIs (Configuration related)

  • You must enable site settings to work on Web API for your portal. Also, you can assign fields of any Entity/Table that your API will modify.
  • First go to make.powerapps.com -> { your environment } -> Portal Management -> {On Left Pane} Site Settings -> Press + New button
  • Power Apps portal settings 1
    Power Apps portal settings 2
  • Create Table Permissions of Target Entity/table for its creation, deleton or modification. Go to Table Permission -> Click + New { for Creation of New Table Permission }
  • Power Apps portal permissions
  • Create a separate Web Role for Web Api that will provide all required privileges as per your need. Go to Web Roles -> Click + New { for Creation of New Web Role }
  • Power Apps portal web roles

Things you should know before you start working on portal Web APIs (Concepts Related)

  • First go to make.powerapps.com / Settings / Customizations / Developer Resources here you will find Instance Web API and accessing the URL you can get data from Dataverse level, it will provide you meta information about the data
  • Power Apps portal web api meta
  • Always use plural name of Entity/Table to get data through Web APIs
  • For getting data of any particular record just type its GUID with () { circle braces } for Instance here is Sample URL for Web API https://yourenv-crm.api.crm.dynamics.com/api/data/v9.2/accounts(a2c4945f-53a3-eb11-b1ac-000d3a53f159)
  • If you want to Target any Entity/Table other than Account or Contact, you have to find its proper name from Odata Metadata, mentioned in above picture.
  • If you want to query any Entity’s/Table’s Column you should always use its schema name. For getting go to make.powerapps.com, solutions, {your solution name}, switch to classic mode, Entities, {specific entity}, Fields, Schema Name Now use can use the schema name along with “@odata.bind” like this imd_account@odata.bind

Portal Operations Using Web APIs

Power Apps portal operations

For a sample AJX call on how to create, update, and delete table records upi can learn more here

Completed solution for our problem statement achieved through Web API

webapi.safeAjax ({ type: "PATCH", url: "/_api/imd_opportunities("+entityId+")", contentType: "application/json; charset=utf-8", data: JSON.stringify({"imd_Contact@odata.bind": "/contacts("+contactId+")" ,"imd_AccountName@odata.bind": "/accounts("+customerId+")"}), success: function (res, status, xhr) { console.log("Status : " + status + " Response : " + res); }, fail: function () { alert ('FAIL'); } });

Learn more about Imperium's Power Apps Portal Services. We hope this information was useful, and we look forward to sharing more insights into the Power Platform world.

References:

  • https://docs.microsoft.com/en-us/powerapps/maker/portals/web-api-perform-operations
  • https://www.ariclevin.com/Home/Post/web-api-powerapps-portals
  • https://www.inogic.com/blog/2021/03/execute-different-web-api-operations-using-powerapps-portals-preview/
  • https://docs.microsoft.com/en-us/powerapps/maker/portals/web-api-http-requests-handle-errors