{"id":41977,"date":"2025-08-08T14:48:08","date_gmt":"2025-08-08T09:18:08","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=41977"},"modified":"2025-08-08T14:48:08","modified_gmt":"2025-08-08T09:18:08","slug":"how-to-call-external-scripts-using-powerapps-component-framework-events-part-1","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2025\/08\/how-to-call-external-scripts-using-powerapps-component-framework-events-part-1\/","title":{"rendered":"How to Call External Scripts using PowerApps Component Framework Events: Part 1"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignnone size-full wp-image-41998\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/How-to-Call-External-Scripts-using-PowerApps-Component-Framework-Events-Part-1.png\" alt=\"How to Call External Scripts using PowerApps Component Framework Events\" width=\"2100\" height=\"1200\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/How-to-Call-External-Scripts-using-PowerApps-Component-Framework-Events-Part-1.png 2100w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/How-to-Call-External-Scripts-using-PowerApps-Component-Framework-Events-Part-1-300x171.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/How-to-Call-External-Scripts-using-PowerApps-Component-Framework-Events-Part-1-1024x585.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/How-to-Call-External-Scripts-using-PowerApps-Component-Framework-Events-Part-1-768x439.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/How-to-Call-External-Scripts-using-PowerApps-Component-Framework-Events-Part-1-1536x878.png 1536w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/How-to-Call-External-Scripts-using-PowerApps-Component-Framework-Events-Part-1-2048x1170.png 2048w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/How-to-Call-External-Scripts-using-PowerApps-Component-Framework-Events-Part-1-660x377.png 660w\" sizes=\"(max-width: 2100px) 100vw, 2100px\" \/><\/p>\n<p>The Power Apps Component Framework (PCF) has long empowered developers to create custom controls for Power Apps, but its interaction capabilities were historically limited.<\/p>\n<p>In model-driven apps, form interactions were confined to some core events, which are OnLoad, OnChange, TabStateChange, and OnSave, tied to the form lifecycle or field updates.<\/p>\n<p>PCF controls could only trigger OnChange by updating a bound field, restricting direct communication with the parent form. Similarly, in canvas apps, PCF controls faced challenges in dynamically interacting with Power Fx expressions or external scripts in a model-driven app.<\/p>\n<p>With the introduction of Events in PCF, these barriers have been significantly reduced. Developers can now define and raise custom events within PCF controls, enabling seamless communication with form scripts in model-driven apps or Power Fx logic in canvas apps.<\/p>\n<p>This blog is part 1 of the PCF events series, where we\u2019ll explore how to leverage Events in PCF to call external scripts in Model-Driven Apps, walk through practical examples, and highlight best practices and use cases to implement these patterns effectively.<\/p>\n<h3><strong>Scenario: Calling our Custom Events in Form Script through PCF control (Model-driven App)<\/strong><\/h3>\n<p>Let\u2019s consider a scenario where an admin configures user-specific features via a User Feature Settings form within CRM. The form includes a PCF component that displays a dropdown of features fetched from a Features List API, including each feature\u2019s name and its supported regions, respectively.<\/p>\n<p>Now, here, instead of binding the onChange event within the CRM, which will require updating our bound field of the PCF control to indirectly trigger form scripts, we created our custom event named featureChange. This event triggers whenever the feature field value changes, allowing seamless interaction of the PCF component within the CRM form itself.<\/p>\n<p>Here is our visual image for our PCF component.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-41978\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/1PowerApps-Component-Framework-Events.png\" alt=\"PowerApps Component Framework Events\" width=\"1664\" height=\"440\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/1PowerApps-Component-Framework-Events.png 1664w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/1PowerApps-Component-Framework-Events-300x79.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/1PowerApps-Component-Framework-Events-1024x271.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/1PowerApps-Component-Framework-Events-768x203.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/1PowerApps-Component-Framework-Events-1536x406.png 1536w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/1PowerApps-Component-Framework-Events-660x175.png 660w\" sizes=\"(max-width: 1664px) 100vw, 1664px\" \/><\/p>\n<p>Now, when the admin selects a feature, the form checks if the feature is supported in the user&#8217;s region and enables the respective settings. If not, a form-level notification is displayed.<\/p>\n<p>Let\u2019s walk through how to implement events in our PCF control with a step-by-step guide to implement events.<\/p>\n<h3><strong>Step-by-Step Implementation<\/strong><\/h3>\n<p><strong>Step 1: Define the Custom Event in the PCF Manifest<\/strong><\/p>\n<p>Define the custom event that the PCF control will expose. This is done in the same way as we define properties in the <em>ControlManifest.Input.xml<\/em><em>.<\/em> Here&#8217;s what the new event declaration looks like:<\/p>\n<p>&lt;event <em>name<\/em>=&#8221;<em>featureChange<\/em>&#8221; <em>display-name-key<\/em>=&#8221;featureChange&#8221; <em>description-key<\/em>=&#8221;The event to handle feature change.&#8221; \/&gt;<\/p>\n<p><strong>Step 2: Implement the Event in the PCF Control (index.ts)<\/strong><\/p>\n<p>In <em>index.ts<\/em>, define a method to fire the event and pass it to your React component via props. Include parameters (e.g., a selected license key) to provide context to the form script.<\/p>\n<pre class=\"lang:css gutter:true start:1\">private <em>handleValidate <\/em>= () =&gt; {\r\nif (this._selectedFeature) {\r\n\r\nthis._context.events.<em>featureChange<\/em>({\r\n\r\nfeatureKey: this._selectedFeature,\r\n\r\nsupportedRegions: this._supportedRegions.map(r =&gt; r.toLowerCase()),\r\n\r\n});\r\n\r\n}\r\n\r\n};\r\n\r\n\u00a0\r\n\r\nprivate <em>handleFeatureChange<\/em>= (key: string, supportedRegions: string[]) =&gt; {\r\n\r\nthis._selectedFeature = key;\r\n\r\nthis._supportedRegions = supportedRegions;\r\n\r\n};\r\n\r\npublic <em>updateView<\/em>(context: ComponentFramework.Context&lt;IInputs&gt;): React.ReactElement {\r\n\r\nconst props: IFeatureControlProps= {\r\n\r\n<em>featureChange<\/em>: this.handleValidate,\r\n\r\n<em>onFeatureChange<\/em>: this.handleFeatureChange,\r\n\r\n};\r\n\r\nreturn React.createElement(FeatureControl, props);\r\n\r\n}<\/pre>\n<p><strong>Step 3: Update the React Component (FeatureControl.tsx)<\/strong><\/p>\n<p>In your React component, define the props interface and bind the event handler to the <strong>onChange<\/strong> of the Dropdown. So, when the user changes the option in the Dropdown, the <strong>onFeatureChange <\/strong>and <strong>featureChange <\/strong>methods will be triggered. The <strong>featureChange <\/strong>is the event that we had set in the Manifest file.<\/p>\n<pre class=\"lang:css gutter:true start:1\">export interface <em>IFeatureControlProps<\/em>{\r\n\r\n<em>featureChange<\/em>: () =&gt; void;\r\n\r\n<em>onFeatureChange<\/em>: (selectedKey: string, regions: string[]) =&gt; void;\r\n\r\n}\r\n\r\nexport const <em>FeatureControl <\/em>= (<em>props<\/em>: <em>IFeatureControlProps<\/em>) =&gt; {\r\n\r\nconst [selectedKey, setSelectedKey] = React.useState&lt;string | undefined&gt;(undefined);\r\n\r\nreturn (\r\n\r\n&lt;div&gt;\r\n\r\n&lt;<em>Dropdown options<\/em>={<em>options<\/em>} <em>selectedKey<\/em>={<em>selectedKey<\/em>}\r\n\r\n<em>onChange<\/em>={(event,option) =&gt; {\r\n\r\nconst key = option?.key as string;\r\n\r\nconst regions = (option as IFeatureOption)?.data?.supportedRegions || [];\r\n\r\nsetSelectedKey(key);\r\n\r\nprops.onFeatureChange(key,regions);\r\n\r\nif(key) { <em>props.featureChange<\/em>(); }\r\n\r\n}}\r\n\r\n<em>placeholder<\/em>=\"Select a feature\"\r\n\r\n<em>styles<\/em>={{ root: { minWidth: 200 } }}\r\n\r\n\/&gt;\r\n\r\n&lt;\/div&gt;\r\n\r\n);};<\/pre>\n<p><strong>Step 4: Update the Existing Form Script (TypeScript Web Resource)<\/strong><\/p>\n<p>Update your existing web resource to handle the featureChange event. Register it on the form\u2019s <strong>on-load event<\/strong> to attach the event handler to the PCF control. So, when the event is triggered from the PCF control, it invokes the method defined in this script &#8211;<\/p>\n<pre class=\"lang:css gutter:true start:1\">namespace IKL{\r\n\r\nexport namespace FeatureControl {\r\n\r\nexport class CheckFeature {\r\n\r\nprivate readonly controlName = \"sha_features\";\r\n\r\npublic <em>onLoad<\/em>(executionContext: any): void {\r\n\r\nlet formContext = executionContext.getFormContext();\r\n\r\nlet featureControl = formContext.getControl(this.controlName);\r\n\r\nif (featureControl ) {\r\n\r\nfeatureControl.addEventHandler(\"featureChange\", (params: any) =&gt; {\r\n\r\nthis.onFeatureChange(params, formContext);\r\n\r\n});\r\n\r\n}\r\n\r\n}\r\n\r\npublic <em>onFeatureChange<\/em>(params: any, formContext: any): void {\r\n\r\n\/\/Here, our logic for enabling settings and showing form-level notification will come.\r\n\r\n}\r\n\r\n}\r\n\r\n}\r\n\r\n}\r\n\r\nlet featureValidate = new IKL.FeatureControl.CheckFeature();<\/pre>\n<p><strong><br \/>\n<\/strong><strong>Summary: What\u2019s Happening Here:<\/strong><\/p>\n<ul>\n<li>We define a custom event (<em>featureChange<\/em>) in the manifest file.<\/li>\n<li>In the PCF control, we fire that event from the React Component when the user selects\/changes the dropdown option.<\/li>\n<li>The JavaScript Web Resource present on the CRM Form listens for that event and executes the logic.<\/li>\n<\/ul>\n<p><strong>Time to See It in Action<\/strong><\/p>\n<p>Now that everything is wired up, event in the manifest, handler in the control, and logic in the form script, you\u2019re ready to test it. Load up your form, interact with the control, and watch how your external script reacts instantly. Smooth, seamless, and finally possible thanks to the PCF Events!<\/p>\n<p>Now, based on the user\u2019s selected feature, the PCF control&#8217;s FeatureChange event enables the corresponding settings. Refer to the screenshots below for a better understanding.<\/p>\n<p><strong><img decoding=\"async\" class=\"alignnone size-full wp-image-41981\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/2PowerApps-Component-Framework-Events.png\" alt=\"PowerApps Component Framework Events\" width=\"1663\" height=\"723\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/2PowerApps-Component-Framework-Events.png 1663w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/2PowerApps-Component-Framework-Events-300x130.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/2PowerApps-Component-Framework-Events-1024x445.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/2PowerApps-Component-Framework-Events-768x334.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/2PowerApps-Component-Framework-Events-1536x668.png 1536w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/2PowerApps-Component-Framework-Events-660x287.png 660w\" sizes=\"(max-width: 1663px) 100vw, 1663px\" \/><\/strong><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-41982\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/3PowerApps-Component-Framework-Events.png\" alt=\"PowerApps Component Framework Events\" width=\"1667\" height=\"605\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/3PowerApps-Component-Framework-Events.png 1667w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/3PowerApps-Component-Framework-Events-300x109.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/3PowerApps-Component-Framework-Events-1024x372.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/3PowerApps-Component-Framework-Events-768x279.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/3PowerApps-Component-Framework-Events-1536x557.png 1536w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2025\/08\/3PowerApps-Component-Framework-Events-660x240.png 660w\" sizes=\"(max-width: 1667px) 100vw, 1667px\" \/><\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>The introduction of Events in PowerApps Component Framework (PCF) has extended its limits of what developers can do with the field-level controls. What once seemed to be a rigid, isolated environment now has a\u00a0more interactive and integrated ecosystem, allowing PCF controls to communicate directly with the Parent Form.<\/p>\n<p>Whether you&#8217;re triggering form script events or updating related fields, Events are a bridge between the PCF control and the CRM form. This capability of Events not only simplifies complicated workarounds but also promotes cleaner, more consistent, and maintainable code.<\/p>\n<p>As you design your next PCF control, consider leveraging Events to create more powerful, flexible, and context-aware experiences across model-driven apps.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Power Apps Component Framework (PCF) has long empowered developers to create custom controls for Power Apps, but its interaction capabilities were historically limited. In model-driven apps, form interactions were confined to some core events, which are OnLoad, OnChange, TabStateChange, and OnSave, tied to the form lifecycle or field updates. PCF controls could only trigger\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2025\/08\/how-to-call-external-scripts-using-powerapps-component-framework-events-part-1\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[44,2361],"tags":[3205],"class_list":["post-41977","post","type-post","status-publish","format-standard","hentry","category-power-apps","category-technical","tag-powerapps-component-framework-events"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/41977","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=41977"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/41977\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=41977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=41977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=41977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}