0

I have added a custom save button in Sales Order screen in place of my current one. How do I reorder the main toolbar so that new save button is in place of the old one? You can do this easily for grid buttons, but for header ones it is not so obvious.

Stan A
  • 133
  • 8

1 Answers1

0

The order of the buttons is based on the order of the PXActions in the graph.

(1) In this example my save button is first, then cancel button second.

enter image description here

public class MyGraph : PXGraph<MyGraph>
{
    public PXSave<MyPrimaryDac> Save;
    public PXCancel<MyPrimaryDac> Cancel;
}

(2) In this example my cancel button is first, then save button second.

enter image description here

public class MyGraph : PXGraph<MyGraph>
{
    public PXCancel<MyPrimaryDac> Cancel;
    public PXSave<MyPrimaryDac> Save;
}

Note that PXSave and PXCancel are PXActions.

Edit: from comments and question edits if you are extending another graph you should be able to use a new class inherited from PXSave and set the property name the same ("Save" in the example of sales order). Here is something that should work for an override to the save button and asking the user a question and keeps the save button in the same button location...

public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
    public SalesPXSave<SOOrder> Save;

    public class SalesPXSave<TNode> : PXSave<TNode> where TNode : class, IBqlTable, new()
    {
        public SalesPXSave(PXGraph graph, string name) : base(graph, name)
        {
        }

        public SalesPXSave(PXGraph graph, Delegate handler) : base(graph, handler)
        {
        }

        [PXSaveButton]
        [PXUIField(DisplayName = "Save", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
        protected override IEnumerable Handler(PXAdapter adapter)
        {
            bool someCondition = true;
            if (someCondition)
            {
                if (adapter.View.Ask(adapter.View.Graph.Caches[typeof(TNode)].Current, "Hi User",
                    MessageButtons.YesNo) != WebDialogResult.Yes)
                {
                    return adapter.Get();
                }
            }

            return base.Handler(adapter);
        }
    }
}

Edit: For reference here are some quick untested examples of extending RowPersisting or the Persist in an extension if this is preferred vs extending the buttons...

[PXOverride]
public virtual void Persist(Action del)
{
    if (Base.Document.Ask(Base.Document.Current, "Question", "Continue?",
            MessageButtons.YesNo) != WebDialogResult.Yes)
    {
        return;
    }

    del?.Invoke();
}


protected virtual void SOOrder_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting del)
{
    var row = (SOOrder)e.Row;
    if (row == null)
    {
        return;
    }

    if ((e.Operation == PXDBOperation.Insert || e.Operation == PXDBOperation.Update || e.Operation == PXDBOperation.Delete) &&
        Base.Document.Ask(row, "Question", "Continue ?", MessageButtons.YesNo, true) != WebDialogResult.Yes)
    {
        e.Cancel = true;
        return;
    }

    del?.Invoke(cache, e);
}
Brendan
  • 5,428
  • 2
  • 17
  • 33
  • What about existing screens like Sales Order? Can I do it via extension? – Stan A Feb 07 '18 at 20:56
  • Are you just trying to add in some logic during the save process? This can be accomplished by overriding Persist() vs trying to override the save button. I need to review this as an extension otherwise – Brendan Feb 07 '18 at 20:59
  • For some reason I thought .Ask() dialog boxes did not work for Persist. Basically, I need to ask a user some question before saving and cancel or proceed with save based on their response. It did not seem to work in RowPersisting for me though – Stan A Feb 07 '18 at 21:12
  • you should be able to create your own Save button inheriting PXSave as I have demoed in the answer update – Brendan Feb 07 '18 at 21:31
  • Persist & SOOrder_RowPersisting should work for asking a question. You can find examples in Acumatica using Ask on both options – Brendan Feb 07 '18 at 21:50
  • Hmm.. can't seem to use any of the methods from the extension. Only static methods. – Stan A Feb 08 '18 at 15:57
  • The use of the extension is not like what you might be thinking when inheriting a class. You have to use PXOverride attributes and the delegate for the base. I can update the answer to include an example. – Brendan Feb 08 '18 at 16:42
  • Hi Brenden, Can you please help me with this requirement - https://stackoverflow.com/questions/64314677/how-to-move-customized-action-button-place-in-existing-screen – Naveen B Oct 14 '20 at 09:49