How To Build a Robust Power Pages File Attachment Pipeline with Microsoft Power Automate

Banner for a How To Series titled How To Build a Robust Power Pages File Attachment Pipeline with Microsoft Power Automate, highlighting parallelism. Featuring Rachel Lowenstein, Technical Consultant, and the New Dynamic logo.

Table of Contents

The more I work with Microsoft Power Automate, the more I appreciate its ability to handle complex data processing tasks. However, one topic that consistently trips up both new and experienced developers is how variables behave inside Apply to Each Loops, especially when parallelism is enabled. If you have ever had a flow that worked perfectly in testing but produced inconsistent or missing data in production, this might be the culprit.

In this article, we will explore how variables interact with Apply to Each Loops, why enabling parallelism can break your flow, and what alternatives you can use to get consistent results.

 

The Solution: A Combination of JavaScript and Power Pages

This approach is especially useful when native or simpler file-upload options begin to show limitations around reliability, scalability, or long-term maintainability in real-world Microsoft Power Pages implementations.

new dynamics javascript power pages

 

JavaScript: Preparing and Sending the File to Microsoft Power Automate

The first component of the solution is the client-side JavaScript executed when a user submits a file along with a Portal Comment (Note), or a user already has a Portal Comment (Note) that they want to attach.

 

1. Capturing the File and the Portal Comment GUID

Begin by retrieving the file input element and extracting the file object that the user uploads. In this example, the file input element has an ID of fileInput:

				
					const fileInput = document.getElementById("fileInput");
const fileAttached = fileInput.files[0];
				
			

This fileAttached object is then passed into the function that will handle sending it to your Power Automate flow (see attachFileToComment function above). The GUID for the related Portal Comment (Note) record is retrieved beforehand and supplied as part of that same call.

 

2. Building the Attachment Function

The function responsible for attaching the file performs several necessary tasks:

  1. Accept the file and portal comment GUID as parameters
  2. Convert the file into Base64 so it can be serialized and transmitted
  3. Build the request payload with:
    • The Base64 file content
    • The Portal Comment GUID
    • The file name
  4. Define the URL of the Power Automate flow that will receive the payload
  5. Execute an AJAX POST to send the structured data to Power Automate

Converting the file to Base64 ensures the content can be safely serialized and transmitted to Microsoft Power Automate using standard request payloads, without relying on custom APIs or unsupported integration patterns.

 

3. Error Handling

Your JavaScript should also capture errors returned by the flow and surface them appropriately to the user interface. With this, the client-side portion of the solution is complete.

 

Power Automate: Handling the File Upload from Microsoft Power Pages

new dynamics power pages file upload new dynamics power pages business logic

The Power Automate flow is responsible for receiving the input, storing the file in Dataverse, and returning a clean response back to Power Pages.

 

1. Accepting Structured Input from Power Pages

The flow begins with the Power Pages trigger, configured to accept three inputs:

  • request – a container for request body metadata
  • commentGUID – the Dataverse identifier for the Portal Comment
  • fileName – the name of the uploaded file

 

2. Initializing a Standard Response Pattern

A single Compose action named response is added early in the flow.
Its structure is:

{ "status": "success" }

This creates a consistent, lightweight response definition that can be referenced at the end of the process.

 

3. Uploading the Attachment to Dataverse

The core step uses the Dataverse “Add a new file” action to store the uploaded content directly in Dataverse.

Configuration:

  • Table: Portal Comments
  • Row ID: commentGUID
  • Column: Attachment
  • Content: Base64 payload from Power Pages
  • Content Name: fileName

By relying on Dataverse’s native file storage, this approach ensures:

  • Proper file metadata handling
  • Compatibility with large files
  • Fewer permission-related issues
  • Long-term sustainability compared to custom API endpoints

Using Dataverse’s native file capabilities also helps align file storage with existing security, governance, and data lifecycle practices already in place for the environment.


4. Sending the Final Success Response

Once the file is uploaded, the flow updates the response to:

{ "response": "Success" }

The return value(s) to Power Pages action then returns this structured message to the JavaScript caller.

 

Conclusion

This combination of JavaScript and Microsoft Power Automate provides a robust and maintainable pattern for handling file attachments in Power Pages. By clearly structuring requests, explicitly defining schemas, and leveraging Dataverse’s built-in file column capabilities, teams can improve reliability and scalability without introducing unnecessary complexity.

More importantly, this approach gives organizations a foundation they can standardize and build on as portal usage grows, requirements evolve, and user expectations increase, helping to ensure file attachments support the overall solution rather than becoming a recurring point of friction.

Working with New Dynamic

New Dynamic is a Microsoft Solutions Partner focused on the Dynamics 365 Customer Engagement and Power Platforms. Our team of dedicated professionals strives to provide first-class experiences incorporating integrity, teamwork, and a relentless commitment to our client’s success.  

Contact Us today to transform your sales productivity and customer buying experiences. 

Join the Community

If you found this blog helpful, subscribe to receive our monthly updates.

Table of Contents

Share with your network

What our Customers Say