{Solved}WebAPI methods in PowerApps component framework (PCF) custom control returning null–Dynamics 365

PowerApps component framework has been like a tsunami hitting the power platform. From customer standpoint, now they are able to achieve any custom UI which otherwise all these days would come back as – “Not supported by Dynamics” from a CRM architect/ consultant. Not only for customers, PCF have been a shot in arm for developer community who finally find their footing in Power platform where they have something unique to contribute, specially those coming from pure web development experience.

PCF controls are everywhere. And if you have developed a PCF control, chances are you must have used the WebAPI methods to interact with CRM data and bind them in PCF controls. To interact with the WebAPI methods, you need to use the context object that gets passed to the init method of your control. For example if you want to create a record, you can use – context.webApi.createRecord method.

The below article explains the  important properties you can access through the context object.

But recently I have been getting loads of queries that context.webApi methods are returning null. Meaning if I try to use the same statement – context.webApi.createRecord.

Honestly I was bit surprised as I have already developed quite a few but didn’t face this error. So decided to give it a try. I took a control I have developed month’s earlier and then tried to re-use it in a latest trial environment. To my surprise, even I was getting that error.

After much try and error and searching the entire manifest documentation with keyword – “webapi”, I came across this Microsoft docs article for schema reference – https://docs.microsoft.com/en-us/powerapps/developer/component-framework/manifest-schema-reference/uses-feature

Pic courtesy – Microsoft Docs.

image

Basically we need to use the “feature-usage” tag and use the WebAPI feature explicitly. Once I put this tag and rebuilt the control, everything just worked fine.

What I believe is with some release Microsoft made it mandatory to use these as opt in feature. Unless we explicitly specify some objects to the load, it won’t load at runtime. Perhaps it’s a way to optimize the performance.

So next time if you get this error, you know which magic tag to include.

Hope this help!

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)


Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe to get the latest posts sent to your email.

2 thoughts on “{Solved}WebAPI methods in PowerApps component framework (PCF) custom control returning null–Dynamics 365”

  1. Hi Debajit,
    I am trying to put a control on form and based on selected data it has to update the form . Is it possible to do that via PCF ? Wondering if there is a way to retrieve entity name and id . Any suggestions .
    Thanks

    1. Hi Manish
      Thanks for reading my blog. Xrm.Page still works inside PCF. You can get recordid and entity name inside PCF using it until Microsoft releases formcontext support inside PCF
      Cheers!
      Debajit

Comments are closed.

Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading