Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Suggested answer

Creating a common helper.ts file for model-driven app forms

(1) ShareShare
ReportReport
Posted on by 618

After writing a lot of TypeScript:  form logic held in multiple files, I thought I would include all my common functions in a helper.ts file. Unfortunately,  after importing it into a Form.ts file, I don't seem to get passed an intialisation error as shown below .

Setup

in my TS folder I have run  (npm) installed : typscript, @types/node and @types/xrm . My event handler logic works fine if I attach the Form.ts to the form and call any function contained it.

MyProjectRootFolder\front-end\ts\src\code\utils\Helper.ts

 // show a simple dialog
   export function displayPromptText(titleText : string, promptText : string)
   {
     let alertStrings = { confirmButtonLabel: "Ok", text:promptText, title: 
     titleText  };
     var confirmOptions = { height: 400, width: 450 }; 
     Xrm.Navigation.openAlertDialog(alertStrings, confirmOptions).then(  
     function (success) {    

     console.log("Dialog closed using OK button.");
     }, function (error) {
      console.log(error.message)
   }  

 )   
}

MyProjectRootFolder\front-end\ts\src\code\forms\MyForm.ts

  import * as helper from  "../utils/helper"
  // also tried this
 // import { displayPromptText } from "../utils/helper";


  // if you call the line below say in Form load you get the intialisation error 
  helper.displayPromptText("test","test");

 

Both Helper.ts and Form.ts transpile to JavaScript without issues.  Whether I import all functions or a single function I don't get passed this error:

 

 

 

  • westerdaled Profile Picture
    618 on at
    Creating a common helper.ts file for model-driven app forms
     
    Thanks very much, I will check out that post and report back.   I thought I would end up using webpack at some stage.
     
    Cheers
     
    Daniel 
  • Suggested answer
    kalluu91 Profile Picture
    34 on at
    Creating a common helper.ts file for model-driven app forms
    I guess that the js bundler does not compile the typescript code correctly.
     
    Check this blog post to have a correct setup for typescript web resource: https://kalcancode.wordpress.com/2025/03/26/how-to-set-up-a-typescript-project-for-power-apps-web-resources/
    The setup shown in the article also includes the utils use case to share the common functions.
     
    Regards,
    Kim Anh

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

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >