Calling Dynamics CRM Rest API from PCF component, Embedding in Model-Driven App

2.6k Views Asked by At

We are working on a Canvas app that allows user to perform bulk operations such as assigning roles to users, manage privileges, etc. For this, we created a custom connector at the PowerApp that calls the Dynamics CRM Rest API to perform various operations using swagger JSON. The Azure AD tokens have been used for authentication.

To avoid various UI limitations and challenges, we are now planning to switch to model-driven app. Two questions:
1. How can we create a PCF component that consumes/call aforesaid Dynamics CRM rest API?
2. How to embed this component on Dynamics CRM model-driven app, so we can use them in Model-driven apps?

1

There are 1 best solutions below

4
On
  1. How to embed this component on Dynamics CRM model-driven app, so we can use them in Model-driven apps?

If you decided to use PCF as your component instead of web resource, better know the limitations. PCF control can be rendered either as a field control or dataset control which means you are going to replace the textbox or subgrid into something else for visualization.

Documentation says:

- Replace a field that displays a numeric text value with a dial or slider code component.
- Transform a list into an entirely different visual experience bound to the data set like a Calendar or Map.
  1. How can we create a PCF component that consumes/call aforesaid Dynamics CRM rest API?

If it’s web resource, we will simply utilize Xrm.WebApi for calling crm web api within HTML/ js webresource in same context.

If it’s PCF, still crm context will support you like this:

this._context.webAPI
      .retrieveMultipleRecords(TSWebAPI._entityName, queryString)
      .then(........

Learn more: Code Reference

Good thing with both of these approach is, no need of extra authentication or token. As they are running inside CRM, current user context will be used. If you want to impersonate some privileged service account for role assignment, it’s possible too using web api header.