In this article, you will learn about the new feature $pages in Power Pages, which is currently in preview (not recommended for production environments). $pages is part of the client-side API that provides powerful tools to interact with your Power Pages site programmatically, making it easier to manage forms, records, and navigation on your site.

The $pages API offers several key functionalities:

1 - Form & Control Manipulation

let forms = $pages.currentPage.forms.getAll();

2 - List Interaction

let lists = $pages.currentPage.lists.getAll();

3 - Web API Access

$pages.webAPI.createRecord(entitySetName: string, data: object):
$pages.webAPI.retrieveRecord(entitySetName: string, id: string, options?: string)

4 - Multistep Form Navigation

let $pages = await Microsoft.Dynamic365.Portal.onPagesClientApiReady();
let form = $pages.currentPage.forms.getFormById('multiform_#1');
console.log(`Form id: ${form.id} has ${form.controls.length} controls.`);

if (form.getVisible()) {
console.log('Form is currently visible.');
}

let tabs = form.tabs;
console.log(`Form has ${tabs.length} tabs.`);

form.goToNextStep();

Right now, the $pages API is accessed through a global variable named $pages (recommended naming convention) after the client API has been initialized.

You can read more about from Microsoft official documentation

Conclusion

In this article, we explored the powerful capabilities of the $pages API in Power Pages, which allows for programmatic interaction with your site’s forms, lists. while $pages is still in preview, it offers valuable tools for building customizable and user-friendly applications, and we can expect even more functionality as it evolves.