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

That is odd - it always has worked for me.

The other way I've seen it done is:

context.page.entityId

but apparently this isn't going to be the supported way.

I have been using below code to access entityId and entityTypeName

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

But I had to use

@ts-ignore

to make it work.

Power Maverick | Microsoft Business Application MVP
Anonymous
Not applicable

Thanks,

 

It's working. Anyway can I access the Form context in the same way ?

 

var formContext = executionContext.getFormContext();

// get formContext // use formContext instead of Xrm.Page

var firstName = formContext.getAttribute("firstname").getValue();

var lastName = formContext.getAttribute("lastname").getValue(); console.log(firstName + " " + lastName);

If you have to access the fields why not use manifest file and use them in control and you can bind them back if you need manipulation to be done and then send it to fields .

@Anonymous Using the formContext in this way isn't supported - although it does work. 

The intension is for the PCF component to be decoupled from the form and only use the parameters to pass data back and forth.

That said, some attribute types are not supported such as Lookups (coming soon), ActivityParty, Customer Fields.

 

For theses, the 'official guidance' is to use a text field to serialise the values back and forth - but that is really awkward and personally until they are supported, I think it's fair to use the form context *for those specific field types* until then - it will be easy to replace out the code once supported.

It's worth re-inforcing that the the form context won't be there when embedding in Canvas Apps - perhaps stating the obvious!

Resurrecting an old thread and I've picked out Scotts post as I've tried both of these to no avail. In init, entitytypename is undefined but it's then defined in updateView - so my question is does anyone know of a way of accessing that data at init level?

I'm not sure that init should have access to the actual data context - it's more an event that allows for starting any setup of your component - updateView is where the data is available for you to bind to. 

 

If you look at the description of init it does imply this:

"Used to initialize the control instance. Controls can kick off remote server calls and other initialization actions here.

   * Data-set values are not initialized here, use updateView."
 
 

My bad for not reading the description - I guess my gut was because I wanted to load a bunch of metadata in init and have it stored for regular use later on.

 

Guess I can handle it a different way, just wasn't my go to code structuring.

 

Thanks as always Scott.

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.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Users online (58,216)