Skip to main content

Notifications

Community site session details

Community site session details

Session Id : qUmct+fitfSbj+tYYLgSu3
Power Apps - Power Apps Pro Dev & ISV
Answered

How to call custom api from PCF component

Like (1) ShareShare
ReportReport
Posted on 28 Sep 2024 04:06:36 by 27
Hello All,
 
I have dynamics’ custom api developed and registered, it returns simple string data. I have PCF which need to call this custom api. But there is no execute method under context.webAPI, so I was wondering what are otherways to call dynamics’ custom api?
 
Thanks
Makarand
  • Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on 30 Sep 2024 at 08:31:41
    How to call custom api from PCF component
    Hi Makarand,
     
    Regarding triggering events: I was talking about triggering them from inside the PCF, which we can . We have a PCF api for that, but only for CanvasApps and CustomPages. I have a blog on this : https://dianabirkelbach.wordpress.com/2023/12/21/pcf-custom-events-sneak-peak/
     
    We can trigger events also in model-driven apps, by using output objects, and using the "addOnOutputChanged" event in form api: https://dianabirkelbach.wordpress.com/2023/05/19/let-your-subgrid-dataset-pcf-communicate-with-the-form/
     
    But your question is the other way around: trigger events from inside a form and catch it in the PCF. The only supported way I know is to use properties bound to your PCF. The updateView will be called when any of your properties gets changed, so you can react that way to events. So instead triggering an event, you make a change to that dedicated bound property,
     
    The code you've posted won't work also because the PCF and the scripts window are different. Probably the PCF is on the top window, and the scripts in an IFrame. You could try to post messages to window.top, but you'll have some issues with the solution checker, since that's not supported.

    Hope this helps!
  • Makarand Keer Profile Picture
    27 on 29 Sep 2024 at 02:38:26
    How to call custom api from PCF component
    Thanks @Diana for helpful tips. 
     
    I would try calling execute and see how it works. 
     
    You also mentioned about triggering custom events (dispatchEvent) from PCF and handling it in Dyanamics form (which in my case is Case form). 
     
    I had different requirements where I wanted to use customEvents triggered from Case form and wanted to catch it PCF, however so far I could not make it work.
     
    Do you have a example which I can follow and get it working in my case?
     
    Here is how I am doing it (I have also posted it as separate question here )
     
    In dyamics case form’s custom js
    window.dispatchEvent(
    new CustomEvent("SKRibbonLoadingEvent", {
    bubbles: true,
    detail: JSON.stringify(caseData),
    })
    );
     
    and here is I tried to catch it in PCF (index.ts), but here handleCustomEvent never gets called
     
    public init(
    context: ComponentFramework.Context<IInputs>,
    notifyOutputChanged: () => void,
    state: ComponentFramework.Dictionary
    ): void {
    this.state = state;
    this.context = context;
    this.userSettings = context.userSettings;
    this.notifyOutputChanged = notifyOutputChanged;
     
    // Add the event listener when the component mounts
    window.addEventListener(
    "SKRibbonLoadingEvent",
    this.handleCustomEvent
    );
    }
     
     
     
  • Suggested answer
    Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on 28 Sep 2024 at 16:40:14
    How to call custom api from PCF component
    Hi Makarand,

    The execute method is there, and it works, but it's not documented... so you can use it, if you know that is unsupported and accept the risk. 
    Do you need it in MDA? I have the feeling that the risk there is not that big, since the form scripting webAPI supports the execute method, so it's basically there.

    If you try to call it supported, it depends....
    One supported way would be to trigger an event from your PCF and let the form-scripting call the execute method.
    In CustomPages you can trigger an event from your PCF and there call the CustomAPI using PowerFx.

    In both cases it depends what you need to do with the result. It could be an input/bound parameter which you set in form-scripting/PowerFx.

    Of  course, there is also the old way of making a change on a record, which triggers the CustomAPI and writes the result back to your record is there too.. (not nice, but works).

    You could also write your own HTTPRequest too. There are some issues you need to take care of in that case (which is the url for webAPI requests inside the maker portal, take care of offline mode , ...).
     
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Power Apps Pro Dev & ISV

#1
WarrenBelz Profile Picture

WarrenBelz 55 Most Valuable Professional

#2
mmbr1606 Profile Picture

mmbr1606 42 Super User 2025 Season 1

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 31 Super User 2025 Season 1

Overall leaderboard
Loading started