mscrm-addons.com logomscrm-addons.com logo
  • Release History
  • Knowledge Base
  • Documentation
  • Contact Support
  • Release History
  • Knowledge Base
  • Documentation
  • Contact Support
home/Knowledge Base/DocumentsCorePack(DCP)/Generate and display documents in Power Pages 

Generate and display documents in Power Pages 

3604 views 0 Updated on February 10, 2025

Microsoft Power Pages enables customers to create professional websites at a fast and low cost. Power Pages is often used to create customer service portals, partner management portals, or event management sites. 

DocumentsCorePack functionalities can be integrated within Microsoft Power Pages to enable users to generate documents from their own webpages and surface them back for users to download. 
 
In this article, we will walk through an example that demonstrates how input into a “donation page” can be equipped with document generation capabilities. 

Prerequisites 

To complete the following example, you will need: 

  • A Power Pages environment 
  • A Power Automate environment 
  • An activated DocumentsCorePack connector 

It is also recommended to have a good understanding of generating documents within Power Automate. 

Our goal: A simple donation form 

Our goal is to create a donation form where users can enter their name, email, and donation information.  Upon submitting the information, a document will be generated and presented to the user.  The form will look similar to the following: 

The donation form
Figure 1: The donation form

The resulting generated PDF will be displayed underneath the form: 

An example generated document
Figure 2: An example generated document

Step-by-Step Video & Tutorial

Step 1: Creating the flow 

Before we even create the form, we will first create the cloud flow for our website. 

Sign into Power Pages.  Choose a website to edit and click on the ❶ Set up button on the left side.  Under Integrations, select ❷ Cloud flows and click on ❸ Create new flow. 

Creating a new cloud flow
Figure 3: Creating a new cloud flow

Search for Power Pages, then select When Power Pages calls a flow.  This will create a flow with the selcted trigger. 

Generate and display documents in Power Pages 
Figure 4: Creating the Power Pages trigger

The inputs to be added to this step should correspond to the inputs we want to include in our form.  For example, if we want to include a “First Name” textbox, then we should also include a “First Name” input to this step. 

Generate and display documents in Power Pages 
Figure 5: Configuring our inputs

Please Note:

Note 1: The input type should match the value entered by the user.  For example, if a textbox accepts only a number value, then the input type in the flow step should be “number.” 

Note 2: Dropdown and/or picklist fields, like the “Category” input shown above, should be added as a number input.  Since the items of these fields are stored internally as a number, they must also be passed in as a number. 

In our example, we want to generate documents based on the entered information, but prevent duplicate contacts from being created if the email is the same. This way, if a donation is submitted, but the email already exists within the system, we will prevent a new contact record from being created. In the case the email does not exist, then a new contact record is generated alongside the donation record. 

To do this, we will check if the contact exists via the submitted email. If it does exist, then we get the contact’s ID and the number of rows. 

Generate and display documents in Power Pages 
Figure 6: The flow steps for checking if the contact’s email already exists

If there indeed exists a contact with the matching email, then we retrieve the contact’s information based on the retrieved ID and proceed. 

Generate and display documents in Power Pages 
Figure 7: Retrieving the contact’s info (using the output of the “Get the ID…” step)

Otherwise, if there is no existing contact with the matching email, we create a new one with the submitted info. 

Creating the contact record with the received inputs
Figure 8: Creating the contact record with the received inputs

Regardless of either case, the donation record is then created in our Dataverse after using the values from our trigger/web-page ´:

Figure 9: Creating the donation record

Then, we add a step to create a document based on the donation record using the “Create document (sync)”-action of the DocumentsCorePack Connector. We use the newly created donation record as the input for our document and choose “PDF” as the output file type.

Configuring the document generation process
Figure 10: Configuring the document generation process

At the end of our flow, we add one final step to return the Document content of the generated document encoded as a string within the “Return value() to Power Pages” action. 

Returning the document content as a string
Figure 11: Returning the document content as a string

Note 3:

When editing the flow after saving, the value for document content may lose the string() encoding. Please double-check this value before saving the flow again. 

Once you finish, name the flow and save it. 

Step 2: Adding the flow to your site 

After creating the flow, we will need to add it to our website to use it for our form. The system will prompt you to add it to your site after you save it. Under Add roles, select Anonymous Users(in our example also unauthenticated users should be able to donate.  Then, add the flow. 

Adding the Anonymous Users role
Figure 12: Adding the Anonymous Users role

Alternatively, if you have already created a flow for Power Pages, you can add the flow under Other cloud flows. 

Adding the flow to our Power Pages website under Other cloud flows
Figure 13: Adding the flow to our Power Pages website under Other cloud flows

Copy the flow’s URL.  We will need this for our website later.

Copying the cloud flow's URL
Figure 14: Copying the cloud flow’s URL

Step 3: Creating the form 

To create the form, begin by creating a blank page for your website. 

Creating a blank page
Figure 15: Creating a blank page

After creating the page, select Edit code to open Visual Studio Code. 

Generate and display documents in Power Pages 
Figure 16: Selecting the Edit code button

In the Visual Studio editor, we will be adding our own custom code. This code contains the labels and inputs for our donation form. 

You can find the full HTML file at the bottom of this article (under “Attachments”) and copy and paste it into the editor. You can see the JavaScript here:

<script>
    document.getElementById("donateForm").addEventListener("submit", function (event) {
        event.preventDefault(); // Prevent form submission

        //Get the relevant divs
        var loadDiv = document.getElementById("loader");
        var viewDiv = document.getElementById("donationView");

        //Get the user's input
        var donation = document.getElementById("donationInput").value;
        var purpose = document.getElementById("purposeInput").value;
        var amount = document.getElementById("amountInput").value;
        var fName = document.getElementById("firstnameInput").value;
        var lName = document.getElementById("lastnameInput").value;
        var category = document.getElementById("donateCategory").value;
        var email = document.getElementById("emailInput").value;

        //Disable or enable divs as needed.  Load wheel is enabled after form submission
        loadDiv.style.display = "block";
        viewDiv.style.display = "none";

        //Create object and store the user's input in it.
        var data = {};
        data["Donation name"] = donation;
        data["Purpose of donation"] = purpose;
        data["First Name"] = fName;
        data["Last Name"] = lName;
        data["Amount"] = Number(amount);
        data["Category"] = Number(category);
        data["Email"] = email;

        //Include the URL to the cloud flow.  This URL should be found under "Set up -> Cloud Flows" in your Power Pages environment.
        var _url = "ENTER YOUR URL HERE";

        //Create payload based on the user input
        var payload = {};
        payload.eventData = JSON.stringify(data);        

        //Pass in the payload and URL to the server
        shell
            .ajaxSafePost({
                type: "POST",
                contentType: "application/json",
                url: _url,
                data: JSON.stringify(payload),
                processData: false,
                global: false,
            })
            .done(function (response) {
                //Get response from server
                const result = JSON.parse(response);     

                //Create and configure the PDF viewer
                var pdfImg = document.createElement("object");
                pdfImg.style.width = "100%";
                pdfImg.style.height = "842pt";
                pdfImg.type = "application/pdf";
                pdfImg.data = "data:application/pdf;base64," + result["document_content"];  //add base64 string
                
                //Get the PDF div
                var newPDF = document.getElementById("donationPDF");

                //Clear PDF div if submit button is used again to prevent multiple PDFs from appearing
                if (newPDF.firstChild) {
                    newPDF.removeChild(newPDF.firstChild);
                    newPDF.appendChild(pdfImg);
                }
                else
                    newPDF.appendChild(pdfImg);

                //Remove the loader and display the link and PDF
                loadDiv.style.display = "none";
                viewDiv.style.display = "block";
              
            })
            .fail(function () {
                loadDiv.style.display = "none";
                alert("An error occurred.");
            });
  });
</script>

Within the script, Change the value of the _url variable to the URL of your own cloud flow, and align all the parameters passed to your input form.

Generate and display documents in Power Pages 
Figure 17: Add your own cloud flow URL to the highlighted variable within the code

After you have added your own cloud flow URL, save the code.  Then return to Power Pages and select Sync.  The page will update and display the donation form. 

Generate and display documents in Power Pages 
Figure 18: The created donation form

Step 4: Testing the form 

To test the page, select Preview. 

Generate and display documents in Power Pages 
Figure 19: Previewing the donation form

Enter your data and click Submit. The system will display the generated document as a PDF below the form after a short time.

Generate and display documents in Power Pages 
Figure 20: The donation form filled with information

Generate and display documents in Power Pages 
Figure 21: The generated PDF containing our submitted information

That’s it! We appreciate your feedback! Please share your thoughts by sending an email to support@mscrm-addons.com. 

Attached Files
#
File Type
File Size
Download
1 .zip 2.68 KB CodeForDonationForm
2 .pdf 1.63 MB DocumentsCorePack_Power_Pages

Was this helpful?

Yes  No
Related Articles
  • Deploying DocumentsCorePack: Setup, Automation, and Real Business Impact in Dynamics365
  • Introducing the DocumentsCorePack Template Designer Office Add-In (Beta)
  • 3 Ways DocumentsCorePack Transforms Proposal, Quote, and Contract Creation
  • DeepSign for DocumentsCorePack 
  • Generate and send a document for e-signing using DeepSign
  • How to prepare a document for DeepSign
Latest Articles
  • What Happens After You Deploy AttachmentExtractor: Storage & Cost Savings in Dynamics 365
  • Deploying DocumentsCorePack: Setup, Automation, and Real Business Impact in Dynamics365
  • Introducing the DocumentsCorePack Template Designer Office Add-In (Beta)
  • How to Eliminate Excess Storage Costs in Microsoft Dynamics 365 Without Losing Access to Emails and Attachments
  • 3 Ways DocumentsCorePack Transforms Proposal, Quote, and Contract Creation
Popular Articles
  • DocumentsCorePack Template Designer – Getting Started
  • Step-by-Step: How to configure a One-Click-Action
  • Application Access for Dynamics 365
  • How to find your environment’s unique name in Microsoft Dynamics 365
  • How licenses are counted
Top Rated Articles
  • “Undefined”-labels in Chrome and Edge 114 and higher
  • Important information for Dynamics 365 online customers using DocumentsCorePack and/or AttachmentExtractor
  • How to activate the DocumentsCorePack Connector for PowerApps & Microsoft Flow
  • How to insert Condition Fields in DocumentsCorePack Templates designer
  • How licenses are counted
Categories
  • *News and General Infos* 64
  • Webinars 45
  • Template Designer(DCP 196
  • DocumentsCorePack(DCP 258
  • TelephoneIntegration (TI 65
  • AttachmentExtractor (AE 75
  • PowerSearch (PS 50
  • ActivityTools (AT 61
  • SmartBar (SB 54
  • GroupCalendar (GC 47
Our Vision

“We see it as our purpose to provide products that simplify and speed up our customers’ Microsoft Dynamics 365 experience.”

Knowledgebase
LogIn
mscrm-addons.com
  • Products
  • Online Shop
  • Downloads
  • My Account
About Us
  • About Us
  • Case Studies
  • Newsletter
  • Partner Program
  • Contact
Support
  • Support
  • Terms & Conditions
  • Documentation
  • Webinars
  • Legal Documents
  • Impressum
  • © 2025 www.mscrm-addons.com. All Rights Reserved.