cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Marius
Level: Powered On

How to access entityId and entityTypeName inside component

What is the correct way to get entityId and entityName of the record the component is located on? From inspection of the context object I have found, that there is:

  • page.entityId
  • page.entityTypeName

Those properties are not contained in the typings. Is it safe to use them? What is the alternative since Xrm.Page is deprecated?

7 REPLIES 7
ben-thompson
Level 8

Re: How to access entityId and entityTypeName inside component

I believe it will eventually become available from within  context.mode.

 

For the moment the best approach is to use

 

let entityId = (<any>context.mode).contextInfo.entityId;
let entityTypeName = (<any>context.mode).contextInfo.entityTypeName;

 

OOlashyn
Level 8

Re: How to access entityId and entityTypeName inside component

Hi @Marius ,

 

There is no OOB way for now. I wrote an article about a workaround about how you can get this information in Model-driven app. A bit of an overkill, however not depend on the undocumented parts of the PCF. You can find it using this link.

ben-thompson
Level 8

Re: How to access entityId and entityTypeName inside component

Sadly the url may not be accurate - in the unified interface it’s possible that the url will relate to the form as a whole while the PCF may be sat in a card belonging to a reference entity (for instance the primary contact card within the account record).

OOlashyn
Level 8

Re: How to access entityId and entityTypeName inside component

Hi @ben-thompson ,

 

Thanks for your reply. Didn't think about that possibility, to be honest. Will update my post to notify about this.

Highlighted
Community Support Team
Community Support Team

Re: How to access entityId and entityTypeName inside component

Hi @Marius ,

I agree with @OOlashyn 's thought almost. Currently, within PowerApps, there is no client API supported in PowerApps Component Framework to get the entityId and entityTypeName of current record.

 

As an alternative solution, please consider take a try with the alternative solution provided by @OOlashyn , then check if the issue is solved.

 

If you would like this client API to be added in PowerApps Component Framework, please consider submit an idea to PowerApps Ideas Forum:

https://powerusers.microsoft.com/t5/Power-Apps-Ideas/idb-p/PowerAppsIdeas

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ben-thompson
Level 8

Re: How to access entityId and entityTypeName inside component

@v-xida-msft and what happens as we follow the roadmap and the form / context of the field is in a parent / child record of the record referenced in the url.

 

I think even back in the 2015/6 days (well before even web refresh) the product team recommended not using the URL to identify the entity being used simply because it might not be 100% accurate.

 

I'm not happy having to comment on a post from a microsoft representative but just because something isn't quite available through the documented API, doesn't make an architecturally unsound approach with known flaws and well documented edge cases a better solution.

Power Apps Staff HemantG
Power Apps Staff

Re: How to access entityId and entityTypeName inside component

Agree @ben-thompson that URL is not the right way. This is currently missing feature in PCF as it needs some design on how these properties will be working on canvas and other model surfaces like grids and dialogs.  We are actively evaluating options here and will share the recommendation on this soon so that there is a established pattern until we add official support.  Priority of the issue is acknowledged.

 

hemant  

Helpful resources

Announcements
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Users online (3,713)