cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dmonks
New Member

Access Page Context within a component

Is it possible to access the page context (at least the entity type and guid of the entity) within a field component. I can understand why you may not wish to make it generally available but it would be useful to offer the option to pass it as a parameter option.

 

 

18 REPLIES 18
HemantG
Power Apps
Power Apps

We are evaluating this ask, it would help if you can share some more details on the target scenario ?

 

As a workaround you can evlaute using input configurable properties. 

Can you share where i would find this example or information? I am also trying to pass the id of the entity that my PCF is embedded on the form. This would be helpful if I want to show a custom visual that requires executing a FetchXml to query the aggregated data.

Anonymous
Not applicable

I would like to see this too.

I have a control bound to a subgrid/dataset. I want to be able to create a new record in that dataset, but in order to do so I need to either:

1. Have the id of the parent entity so that I can use the webapi.

or 

2. Have a way to add a record to the dataset passed to the control.

It doesn't appear that I can do either?

 

Thanks

Jason

vigneshR
Frequent Visitor

 

Hi @dmonks, @Anonymous, @davallen,

 

If I am not wrong you could use below format to get the entity Id and EntityType of the form on which the custom control is added.

 

Capture_EntityrReference.PNG

 

you can refer below post for example code 

https://powerusers.microsoft.com/t5/PowerApps-component-framework/i-want-to-get-relevent-data-about-powerapps-component-framework/m-p/352299/highlight/true#M805

 

Please Feel free to mark the answer as verified if it is useful

Regards,

Vignesh.R

 

There are actually two ways of getting the entityId and type name:

mode (https://docs.microsoft.com/en-us/powerapps/developer/component-framework/reference/mode)

 

context.mode.contextInfo.entityId
context.mode.contextInfo.entityTypeName
context.mode.contextInfo.entityRecordName

Or Page (not documented at all)

 

context.page.entityId
context.page.entityTypeName

Neither of these are documented. @HemantG Are either of these supported?

This is in the back log and will be added in near future.  To unblock you can use in the interim  (not officially supported though)

context.mode.contextInfo.entityId
context.mode.contextInfo.entityTypeName

 

The final sematics will be communicated but are expected to be inline with above and hence control update should be straightforward. 

 

hemant 

Have you tried declaring entityReference at the class level :

 

private _entity: ComponentFramework.EntityReference;

 

and later on in function this._entity.name, this._entity.id.guid to get the current record data . 

 

Thanks 

Anonymous
Not applicable

Hello Scott,

 

I've tried to use context.mode.contextInfo.entityTypeName but I faced the following error message:

 

Property 'contextInfo' does not exist on Type 'Mode'

 

any workaround to get the EntityId and/or EntityName ?

Thx

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Users online (67,573)