What does “context” object hold in Power Apps custom component framework. Organization info, user info, web API methods and more!

After my detailed post on Power Apps Custom component framework, I have getting loads of queries and among them the common ones are

  • How do we get organization details within my Power Apps custom control
  • How to get context user information
  • How to get record information on which the control  is embedded
  • How to query Web API from my control code.

The answer to all of these lies in the context object that gets passed to the init method of your control. Just like with Plugin context, the control context contains all information about the current environment in which it is executing.

So let’s explore what the context has in store for us. And what’s better way than the wonderful developer tools of Chrome browser. Below is a screenshot of the property bag that context contains.

image

The important ones I just highlighted. So let’s go a bit granular on the highlighted one.

1. page:

context.page can help you with useful values like the id of the current app which is loaded, the guid of the record and the logical name of the record on which the control is showing up.

And also our very own lovable method – getClientUrl().

image

2. orgSettings

I think the name justifies all. This gives us all the values related to the CRM organization. And this is the same one you get when you query for Organization Settings using Xrm.Utility.getGlobalContext()

image

3. userSettings

This will give you information about the logged in user security roles, language code, user id etc.

image

4. webAPI

Well this can be very important. Specially if you want to query CRM web api from your control. Here you get all the methods to communicate with CRM Web API.

image

Hope that gives you all the information to get started with your first custom component.

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

Multiselect picklist for Dynamics 365 (http://www.xrmforyou.com/multi-select-picklist.html)

5 thoughts on “What does “context” object hold in Power Apps custom component framework. Organization info, user info, web API methods and more!”

  1. Birgit Nauwelaerts

    I saw in your example, you used a reference to Xrm.Page to get the logical name of the attribute.
    I don’t seem to find anywhere documentation what is available for parameters.
    In my current project we’re discussing to use a custom control, but we need to know if a field is required.
    However we are online and Xrm.Page will be no longer valid.
    Wondering if there is a way to use the parameter itself to get this kind of information?

    1. Hi Birgit,
      Thanks for reading my blog. For sake of time and length I have used Xrm.Page and also mentioned it is deprecated. Actually I did’t find any way to get the form context but what you can do is store the formContext in a global variable which should be available inside your component code. Let me see if I can try it. I will let you know.
      Cheers!
      Debajit

  2. Hi Debajit ,
    I was just reading your blog.I want to update the record in crm through my custom control but webapi object is null for me.
    Any idea for this.

Comments are closed.