Dynamics 365 Business Central: Run code in an action without using the OnAction trigger (RunObject, RunPageLink, RunPageMode, RunPageView, and RunPageOnRec)

Dynamics 365 Business Central

Hi, Readers.
Today I would like to share a mini tip for adding custom actions in Business Central, how to run code in an action without using the OnAction trigger.

The page actions are displayed on the header section. There are multiple tabs to help navigate to the right item.

We generally use OnAction (Action) trigger to run code when a user selects an action on a page. For example,

Very simple. In fact, we can do some same processing through RunObject Property. Let’s see more details.

RunObject Property: Sets the object (such as pages, reports, codeunits, and queries) you want to run immediately when the action is activated.

We can also use RunPageLink Property to add default filters for the opened page.
RunPageLink Property: Sets a link to a page that will be launched for this action.
A simple example,

Test video: Multiple selection is not supported

This is used extensively in the standard.

And if you use OnAction (Action) trigger to do this, you need to write the following code.

There are also two related properties.

RunPageMode Property: Sets the mode in which the page is run. Choose between View, Edit, or Create.

ValueAvailable or changed withDescription
Viewruntime version 1.0The page is run in View mode.
Editruntime version 1.0The page is run in Edit mode.
Createruntime version 1.0The page is run in Create mode.

More details: Dynamics 365 Business Central: How to open a page in Create/New mode via AL

RunPageView Property: Sets a tableview for the page that will be launched for this action.

You determine what records the user can see by setting filters, determining the sorting order, and selecting the keys. You can use this property to indicate how information should be sorted.

For example, this is somewhat similar to SourceTableView Property (Pages)

Finally, there is one more property.
RunPageOnRec Property: Sets the same record on the page you launch from this control as is already displayed on the current page.
The following is a standard example.

Using this method is sometimes simpler than writing code directly. So Microsoft gave the following suggestions.

You typically use the RunObject Property to run objects such as pages, reports, codeunits, and queries from an action. You can use the OnAction trigger when you require more processing than the RunObject Property can support, such as filtering data before a page is displayed or writing to the database.

Is this true? Because codeunits can be set in RunObject Property, if we transfer through codeunits, we can also accomplish complex processes. For example,

Please note that this way can only execute the OnRun (Codeunit) trigger in the codeunit, but cannot execute the procedure. Therefore, each action will use up a codeunit, which is why it is generally not done this way…..

And the OnAction (Action) trigger is not used on Role Center pages.

We can also use this way. When you select the action, OnRun (Codeunit) trigger in the codeunit will be executed. This is similar to execute the OnAction Trigger in the action. More details: Dynamics 365 Business Central: OnAction trigger on Role Center pages (Error: A page of type Role Center cannot have triggers)

Great. When you add new custom actions, be sure to consider this approach as well. Give it a try!!!😁

PS:
1. Dynamics 365 Business Central: What is Promoted action and How to Promote action?

2. Business Central 2022 wave 2 (BC21): Promoted action groups, action references, and ShowAs Property (New Modern Action Bar)

3. Dynamics 365 Business Central: Hide and show actions dynamically

4. Business Central 2023 wave 1 (BC22) new features: Provide Title and custom actions to Error dialogs (Custom Actions in error messages)

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL