Monday, 24 July 2017

Actions and Primary View

Hi There,

Today we are going to speak about Actions in Acumatica, as well known as Buttons.

When you creating a button you basically just need to write a simple code snippet like here:
#region Event Handlers
public PXAction<PX.Objects.GL.BatchMyButton;  
[PXButton(CommitChanges true)]
[PXUIField(DisplayName "My Button")]
protected void myButton()

As soon as you add this button as extension and publish it, you will see button appeared on the screen.
But from platform standpoint there is much more than button handler, let check how does it work:

Action Data View - "public PXAction<BatchMyButton;"
PXAction is special version of Data View in Acumatica, that defines action name, as well as button handler name. But you may see that Action has a generic parameter - DAC, which identifies primary view to which this action is attached.
As you may know from training guides, that one screen, as well as one graph, can have only primary view, that you specifying here:
And here:
Plus you putting primary view in Action... So the question is - why we need to to put primary view in 3 places if for one graph we have one screen.
Unfortunately the answer is "Historical Reasons". Some time ago there was possibility to have multiple screens for one graph, and in that case you may need to choose what is primary view for that or that screen (that is why you have primary view in ASPX page) and you also nee to choose what action is visible on what screen (that is why we have primary view in action).

Right now it is not really needed, but we still have to link Actions to primary view - primary view from page should have same main DAC as Action, otherwise action would not be visible on the screen.

Button Handler - "protected void myButton()"

This method we call button handler delegate. This method must have the same name (except the register) as action Data View, otherwise it will not be executed. Naming or Actions and Methods is just a naming convention in Acumatica.

Attributes - "[PXButton(CommitChanges true)]"
Attribute is a place where you can control how button will appear on the interface or how button will perform.
There are many attributes allowed to be on button handler, but main things what you most probably need to have is "PXButton" and "PXUIField" attributes.

Callback Command - "<px:PXDSCallbackCommand Name="Action" />"
Callback command in data-source is an optional place where you can configure UI field behaviors.
Right now we are moving away from having these parameters on ASPX and trying to make as more configurations as we can in server code.
However there are some important things that we cannot remove now, for example "Visible" property. Only pace can decide now if the action is visible on data-source or not..

Hope that this information is helpful for you!
Have a nice development

No comments: