Parameterizing Page Scripting Tool Scripts in Microsoft Dynamics Business Central
Introduction
In the world of Microsoft Dynamics Business Central, efficiency and flexibility are key. One way to achieve this is by parameterizing your page scripts. This approach allows you to modify and reuse scripts easily without the need to change multiple instances of a specific value within the script. This BLOG is based on the preview version of the page scripting tool, version 24, so this BLOG post may very well not remain relevant in future versions, but for now, it works. So today, we'll explore how to parameterize your scripts using a practical example.
What Does It Mean to Parameterize a Script?
Parameterizing a script involves defining variables that can be used throughout your script instead of hardcoding specific values. This makes the script more flexible and easier to maintain. For instance, if you have a script that filters a customer list by a specific customer number, parameterizing the customer number allows you to change the customer number in one place rather than updating it throughout the script.
Example: Parameterizing a Customer Filter Script
Let's take a script that opens the list of customers, filters to customer 10000, opens the customer card, and validates that the correct customer has opened. We'll then transform it into a parameterized script where the customer number is a parameter.
Original Script
Here’s the original script:
name: Cust10000
description: Test recording
start:
profile: BUSINESS MANAGER EVALUATION
steps:
- type: navigate
target:
- page: Business Manager Role Center
- action: Customers
description: Navigate to <caption>Customers</caption>
- type: page-shown
source:
page: Customer List
modal: false
runtimeId: b4r3
description: Page <caption>Customers</caption> was shown.
- type: filter
target:
- page: Customer List
runtimeRef: b4r3
operation: add
column:
field: No.
scope: filter
description: Add filter for <caption>No.</caption> on <caption>Customers</caption>
- type: input
target:
- page: Customer List
runtimeRef: b4r3
- scope: filter
field: No.
value: "10000"
description: Input <value>10000</value> into <caption>No.</caption>
- type: invoke
target:
- page: Customer List
runtimeRef: b4r3
- repeater: Control1
invokeType: Edit
description: Invoke row on <caption>Control1</caption>
- type: page-shown
source:
page: Customer Card
modal: false
runtimeId: b5d1
description: Page <caption>Customer Card</caption> was shown.
- type: validate
target:
- page: Customer Card
runtimeRef: b5d1
- field: No.
operation: =
value: "10000"
description: Validate <caption>No.</caption> <operation>is</operation>
<value>10000</value>
领英推荐
Parameterized Script
Now, let's parameterize the customer number in this script:
name: Cust10000
description: Test recording
parameters:
CustomerNo:
type: string
default: "20000"
start:
profile: BUSINESS MANAGER EVALUATION
steps:
- type: navigate
target:
- page: Business Manager Role Center
- action: Customers
description: Navigate to <caption>Customers</caption>
- type: page-shown
source:
page: Customer List
modal: false
runtimeId: b4r3
description: Page <caption>Customers</caption> was shown.
- type: filter
target:
- page: Customer List
runtimeRef: b4r3
operation: add
column:
field: No.
scope: filter
description: Add filter for <caption>No.</caption> on <caption>Customers</caption>
- type: input
target:
- page: Customer List
runtimeRef: b4r3
- scope: filter
field: No.
value: =Parameters.'CustomerNo'
description: Input <value>=Parameters.'CustomerNo'</value> into <caption>No.</caption>
- type: invoke
target:
- page: Customer List
runtimeRef: b4r3
- repeater: Control1
invokeType: Edit
description: Invoke row on <caption>Control1</caption>
- type: page-shown
source:
page: Customer Card
modal: false
runtimeId: b5d1
description: Page <caption>Customer Card</caption> was shown.
- type: validate
target:
- page: Customer Card
runtimeRef: b5d1
- field: No.
operation: =
value: =Parameters.'CustomerNo'
description: Validate <caption>No.</caption> <operation>is</operation>
<value>=Parameters.'CustomerNo'</value>
Step-by-Step Guide to Parameterize Your Script
Benefits of Parameterizing Your Scripts
Conclusion and Disclaimer
As mentioned in the beginning, this is based on version 24 of Business Central, and the Page Scripting Tool is still in Preview, which means that features may very well change in future, or Microsoft may make it easier for us to achieve the same result. For now this is how the page scripting tool is working. Give your feedback if you would like to see features in this tool on https://aka.ms/BCIdeas and help shape the future of this tool. Be careful not to invest too heavily into developing scripts for this tool until the tool is in it's final release, happy scripting.
Parameterizing your scripts in Microsoft Dynamics Business Central is a powerful technique to enhance your automation workflows. By following the steps outlined above, you can create flexible, maintainable scripts that save you time and effort. Start parameterizing your scripts today and experience the benefits of a more streamlined process!