Running Automaton Button from code

Hi All,

Here I want to share one example of customization. We want to trigger a button that is defined as Automation action from code. The problem here is that the button is not defined in the code, so we need to trigger it the same way how UI does it.
To do this we have do several tricks:

  • Define a new custom PXView that will return record that we want to process
  • Create an adapter, that will provide data for button handler. Adapter will get data from custom PXview.
  • Create a separate instance of graph, that will handle action.

Code example with comments:

Big thanks to Acumatica support team for the provided example.
Have a nice development.

4 Replies to “Running Automaton Button from code”

  1. In 2018r2 the code should be a bit different. It should look like that:
    SOOrderEntry graph = PXGraph.CreateInstance();
    SOOrder order = PXSelect<SOOrder, Where<SOOrder.orderNbr, Equal<Required>>>.Select(graph, “SO004627”);

    //creating a graph that will process Internal command
    graph.Document.Current = graph.Document.Search(order.OrderNbr, order.OrderType);

    //Searching for correct button from that is defined in Automatin steps.
    //All sub menues are adden under action button, so we can get them and iterate.
    foreach (var action in (graph.action.GetState(null) as PXButtonState).Menus)
    if (action.Command == “Cancel Order”)
    //Constructing dummy view that will always return only one record.
    adapter = new PXAdapter(new PXView.Dummy(graph, graph.Document.View.BqlSelect, new List { order }));
    //defining a button command
    adapter.Menu = action.Command;

    //running button
    var dict = new Dictionary();
    PXAutomation.ApplyAction(graph, graph.action, “Cancel Order”, graph.Document.Current, out dict);
    PXAutomation.GetStep(graph, new List { graph.Document.Current }, graph.Document.View.BqlSelect);

  2. Hi Hari,
    There was a good example, how to pass custom field from AP Doc to GL in Acumatica Customization guide and previous customization training. Could you please check it.

  3. Good Article Sergey,

    How about to customize screen Release AP Documents (AP501000) in Acumatica ERP System, if using additional field. Passing Customize field's value from screen AP301000 and sent in to Journal Transactions screen using Release All button in screen (AP501000) ?

Leave a Reply

Your email address will not be published. Required fields are marked *