cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

PCF-React Control Using webAPI

Hi Folks,

Im a frontend developer and new to PCF and Powerapps component framework. I'm trying to retrieve data from an entity using retriveRecord but was not working even after deployed. 

This is the code which i have used in the pcf control.I'm aware about the webAPI not supported in the test harness but In the test harness at least I'm getting the error response. After deploying the control we are not getting any success or error console logs.

 

We are also getting a authentication error from skype-sdk file.

 

(the id and entity logical name is dummy here)

 

const retriveData=async () => {
console.log("log from retriveData");
let id="1";
let filter=`$select=firstname,lastname`;
let options="";
props.pcfContext.webAPI
      .retrieveRecord("leads", id, filter)
      .then(successCallback, errorCallback);
  };
const successCallback= (response: any) => {
console.log(response, "WebApi succss Response");
alert("sucess");
  };
const errorCallback= (errorResponse: any) => {
console.log(errorResponse, "WebApi error Response");
alert("error");
  };

 

 

 

Any help work appreciate!

Krishna

11 REPLIES 11
Highlighted
Super User
Super User

Hi @imkp93 

I think it's only a small issue: is should be "lead", not "leads":

 

props.pcfContext.webAPI
      .retrieveRecord("lead", id, filter)
      .then(successCallback, errorCallback);

 

And because successCallback and errorCallback are declared with const (not function), they should be declared before using them.

Hope this helps!

 

Kind regards,

Diana 

Highlighted

@DianaBirkelbach 

 

Thanks for your replay, and I tried this but it still remains the same. I tried to log the context in the console. And Its not showing the available webAPI methods like retrieveRecord under the webAPI. It should show these methods there right? then only we can consume it.

 

utils: e {_customControlProperties: {…}, _externalUtils: {…}, _globalCommandManagerInitialized: false, _internalEventListeners: Array(1), doesControlExist: ƒ, …}
webAPI: e
__proto__: Object
__proto__: Object
Highlighted

@imkp93 did you enable webapi in ControlManifest.Input.xml? It should look like following:

    <feature-usage>
      <uses-feature name="Utility" required="true" />
      <uses-feature name="WebAPI" required="true" />
    </feature-usage>
 
Highlighted
Frequent Visitor

@a33ik 

 

yes I have added those. and in the test harness it throwing error response (retrieveRecord method). But after deploying it , looks like it not executing the method.

Highlighted

Hi @imkp93 ,

It should work then. You are testing in a Model-Driven, and not in a CanvasApp, right?

Kind regards,

Diana

Highlighted

@DianaBirkelbach 

 

we are trying to import this pcf control into a Microsoft dynamics 365. It is Model-Driven right?

Highlighted

Hi @imkp93 ,

I have an example where only "utils" were activated in the manifest, but not the "webAPI", and is looking exactly like in your screenshot:

DianaBirkelbach_0-1601558315840.png

It looks like the webAPI is not activated in your control.

In case you activated first the "utils", and the webAPI later on, maybe you have a problem with the upload of your component (so maybe it didn't made the update correctly).
Do you use "pac pcf push" to upload the PCF?

Kind regards,

Diana

PS: Yes, Dynamics 365 is ModelDriven App 🙂

Highlighted

 

 

Yes @DianaBirkelbach , we are using "pac pcf push" to upload the PCF control.

 

 

Kind Regards

Krishna

Highlighted

Hi @imkp93 ,

 

Then I also think that it should work. Here is all I can still think of:

1.  the webAPI functions are visible in the console only when you open the "__proto__" property (Screenshot below), so maybe it's still there. I just wonder, why you have the __proto__ listed twice.

DianaBirkelbach_0-1602068855750.png

 

 2. delete the PCF from your form

 3. check again in the manifest that webApi feature is set to true (as @a33ik described)

 4. If you use "pac pcf push", this will generate the content of the solution inside as subfolder of your project. Check out here "\obj\PowerAppsTools_<yourPrefix>\bin\Debug\PowerAppsTools_<yourPrefix>.zip", and check inside of your manifest if the features are correct. Check if you have included some other content in the zip that shouldn't belong there.

 5. register again the PCF on the form.

 6. If it still doesn't work, you could try to make a dummy webAPI request right inside your updateView method. I see that you use props.pcfContext which makes me think that maybe you've passed the pcf context as props inside a React component. Maybe is a react issue.

 

If that still doesn't work, I'm afraid I have no ideas anymore... Wish you luck!🍀

 

Hope it helps!

Kind regards,

Diana

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Users online (12,915)