top of page
Blue Background

Resources - BLOG

Creating Macros in Business Central with Page Scripting

  • Writer: John Ellis
    John Ellis
  • Aug 26
  • 2 min read

Updated: Sep 4

Last September we published a blog article on Business Central’s Page Scripting -- a feature which records events such as opening pages, entering data in fields, and selecting actions.

 

Conventionally, these recordings are used to review the results of User Acceptance Testing.

 

We at Turnkey Technologies have discovered another use for this feature – creating macros!

 

Please follow this guide to learn how to create macros in Microsoft Dynamics 365 Business Central using Page Scripting.



Steps to Creating Macros in Business Central with Page Scripting



Recording


Click the “Settings” button found in the top right-hand corner of Business Central, to open Page Scripting:


Settings menu in Dynamics 365 Business Central, listing options like Personalize, Design, and the circled "Page scripting (Preview)".

Illustration of a computer screen with a head icon. Text explains page scripting for Business Central. Buttons: "Start new" and "Open."

After clicking the “Start new” button shown above, click the red dot to begin recording:

Recording toolbar with playback controls: record, stop, pause. "Page Scripting (preview)" title. Text: "Recording (no steps recorded yet)".

For this recording, you can open and close a Sales Quote.


Once you have concluded recording, click the “Stop” button.



Saving the Recording


Click the ellipsis button at the top of Page Scripting, to save the test as a “YAML” file:

"Page Scripting preview with open save dialog for 'Recording.yml' file in folder path. Text includes page actions and commands. Neutral mood."

As a refresher from the previous article, “YAML” is a data interchange file and more information may be found at yaml.org.



Replaying


To replay these steps and determine if testing was successful, click the “Play” button:

Automation tool window showing successful script actions: Invoking, focusing, and closing a "Sales Quote" page. Completed steps are marked.

In clicking Play, the Sales Quote will reopen and reclose.



Editing the Recording


Opening and editing this YAML file in Notepad will, in essence, program Business Central to conduct other operations besides opening and closing a Sales Quote!


For example, what if you want to create a Sales Order instead of a Sales Quote?

It’s simply a matter of editing the file!


 

Transforming the Recording into a Macro


Here is the YAML file, as opened in Notepad:

name: Recording

description: Test recording

start:

  profile: BUSINESS MANAGER

steps:

  - type: invoke

    target:

      - page: Business Manager Role Center

        runtimeRef: b0

      - action: Sales Quote

    description: Invoke <caption>Sales Quote</caption>

  - type: page-shown

    source:

      page: Sales Quote

    modal: false

    runtimeId: bb6c

    description: Page <caption>New - Sales Quote</caption> was shown.

  - type: focus

    target:

      - page: Sales Quote

        runtimeRef: bb6c

      - field: Sell-to Customer Name

    description: Focus <caption>Customer Name</caption>

  - type: close-page

    target:

      - page: Sales Quote

        runtimeRef: bb6c

    description: Close page <caption>New - Sales Quote</caption>

  - type: page-closed

    source:

      page: Sales Quote

    runtimeId: bb6c

    description: Page <caption>New - Sales Quote</caption> was closed.

 

Within this file, conduct a find on “Quote” and replace with “Order”.


Once the file is saved with this change, browse out to the file:


A computer window titled "Page Scripting (preview)" shows recording options with buttons and a dropdown menu listing "New recording" and "Open recording."

Pressing the “Play” button creates a new Sales Order in Business Central.


The “before” and “after” screenshots, shown on the next page, prove this.


before

Spreadsheet showing sales orders with columns: order number, customer number, customer name, location code, and document date. Highlights in turquoise.

after

A sales order list features entries with numbers, customer names, and document dates. The row for Adatum Corporation is highlighted in blue.

S-ORD101048 is a new Sales Order created by this macro!


Security and Other Considerations


To record, your user account must have the “PAGESCRIPTING – REC” permission set or equivalent permissions.

 

To play a recording, your user account must have the “PAGESCRIPTING – PLAY” permission set or equivalent permissions.

 

(Testing of the new “Page Scripting” feature for this blog article was conducted in application version 26.3.36158.37931.)


For help or support, please feel free to contact us.



bottom of page