Power Pages: Single WebAPI Call for Parent-Child Records
Image Source: Shutterstock.com
Power Pages
Oct 30, 2023 11:00 AM

Power Pages: Single WebAPI Call for Parent-Child Records

by HubSite 365 about Michel Mendes [MVP]

Microsoft MVP | Senior Consultant at Avanade | Microsoft 365 | Power Platform | SharePoint

External Blog Post
Citizen Developer

Power PagesLearning Selection

Learn to create a record and child records in Power Pages with a single WebAPI call with our comprehensive Microsoft guide.

Using Power Pages to Create Parent and Child Records with One WebAPI Call

The blog post written by Michel Mendes [MVP] presents a clever way to use Power Pages to create parent and child records in one move. He emphasizes that it's impossible with default forms. However, a simple WebAPI call in Power Pages solves the problem.

He uses an example of creating an Account with two Contacts. It is vital to note that both the Account and Contact tables must be enabled for the WebAPI, enabling the fields used in the WebAPI call for both tables. You also need the right table permissions for users to create items and link contacts with accounts.

In addition, a 'WebAPI' wrapper should be included in a web template to use the webApi.safeAjax function, detailed later in his blog post. More on Power Pages here.

How to Set Up The Request

Michel then offers clear instructions on setting up the request to create these records. Define a variable or constant you need to submit. It should contain all fields from the parent object (account), and the array of child objects under a property with the relationship name for that parent-child chain.

A POST request can then be run to the appropriate API endpoint for the parent record table, using the webApi.safeAjax method as provided in the blog post. It includes all necessary details for the call: names, telephone numbers, and emails.

After running a single WebAPI call as described, parents and children records are created in the Power Pages and visible in the Dataverse. It ensures efficiency and clean organization of web tables for optimal record-keeping.

Tapping into the versatility of Power Pages goes beyond the simplicity of creating or associating records. Tools like WebAPI calls offer unlimited potential in easing data organization and management.

Keep exploring and discovering new ways to make the most of Microsoft's dynamic platforms. Join the ongoing conversation on how to optimize your work with Power Pages, Dataverse, and other Microsoft solutions.

Read the full article Create parent and child records with a single WebAPI call in Power Pages

Power Pages - Power Pages: Single WebAPI Call for Parent-Child Records

Learn about Create parent and child records with a single WebAPI call in Power Pages

When dealing with the innovative platform known as Power Pages, there are instances where you may want to create a record along with its sub-records. For a scenario such as this, the built-in forms don't offer a solution. Nevertheless, a feasible approach exists in the form of using Power Pages' Web API, as it allows you to execute this action with just a single call.

Many practical examples can illustrate how this can be done, but in this blog post, we'll focus on creating an Account that features two child Contacts in the versatile Power Pages system. To effectively employ this technique, certain prerequisites must be put in place.

  • Firstly, both the Account and Contact tables need to be enabled for the WebAPI. Details for that can be found here.

  • Secondly, the fields that will be employed in the WebAPI call for both tables should be enabled. This requirement includes the relationship field. Check more about it here.

  • ,

    Thirdly, you need to have the correct table permissions configured. This setting ensures users can generate items and link contacts with accounts. Find more information on table permissions here.

  • Lastly, include the 'WebAPI' wrapper (a sample from Microsoft) in a web template, enabling the usage of the webApi.safeAjax function. Instructions for this are detailed here.

Once your setup checks all the boxes with regard to the prerequisites, you'll want to focus on setting up the request next.

You will need to define a variable or constant, something along the lines of an object that you'll later submit. The object needs to contain all fields from the parent object (account) and the array of child objects (contacts). These must be placed under a property bearing the relationship name for that specific parent/child relationship scenario, which in this case will be contact_customer_accounts. It is critical to get the precise relationship name for the records that will be captured.

Afterward, you will run a POST request to the API endpoint that's assigned to the parent record table, using the method webapi.safeAjax. The process of how to go about this has been demonstrated in the detailed code snippet provided.

On successful implementation of the WebAPI call, you will manage to create the parent and child records in the robust Power Pages platform, which will then show up in Dataverse. You can view the evidence of this successful execution as seen in the screenshot provided.

To delve more into the topic of creating parent and child records via a single WebAPI call in Power Pages, you can head over to this blog post. It promises to offer a detailed guide with additional insights that will put all lingering questions to rest.

More links on about Create parent and child records with a single WebAPI call in Power Pages

Create parent and child records with a single WebAPI call ...
3 days ago — By running a single WebAPI call as above, the you can parent and child records are created from Power Pages and appear in Dataverse: Share this:.
Create Parent - Child Record in Single D365 Web API ...
Mar 14, 2022 — POST request is used to create a record, So we'll use POST request to create Parent – Child record. Select the POST request, ...
Overview of the Power Pages portals Web API
Sep 15, 2023 — Learn how to use the portals Web API to create, read, update, and delete Microsoft Dataverse tables from your Power Pages sites.

Keywords

Power Pages Create Records, WebAPI Call Power Pages, Parent Child Records Power Pages, Single WebAPI Call, Power Pages WebAPI Tutorial, Create Records Power Pages, Power Pages Parent Child, WebAPI Power Pages, Create Power Pages Records, Child Records Single Call Power Pages