Skip to main content

I have added a custom Action Button “CustomApprove” that I press it through an event handler. This action button then displys a SmartP Panel “RoutingPanelDialogData” with OK/Cancel buttons. When user clicks on OK, I expect the method resume from the point displayed the smart panel but when I trace doesn’t hit this point at all. Can some advise what Im doing wrong?

Here is my Event Handler:

        protected void EPApproval_RowInserted(PXCache cache, PXRowInsertedEventArgs e) //, PXRowInserted InvokeBaseHandler)
{
//InvokeBaseHandler?.Invoke(cache, e);

APInvoice document = Base.Document.Current;
EPApproval approval = e.Row as EPApproval;

EPApproval approvalPrev = PXSelect<EPApproval,
Where<EPApproval.refNoteID, Equal<Required<EPApproval.refNoteID>>,
And<EPApproval.status, NotEqual<Required<EPApproval.status>>,
And<EPApproval.approvalID, NotEqual<Required<EPApproval.approvalID>>>>>,
OrderBy<Asc<EPApproval.approvalID>>>
.Select(Base, approval.RefNoteID, EPStatuses.Pending, approval.ApprovalID).LastOrDefault();

if (document.Status == APDocStatus.PendingApproval && approval.Status == EPStatuses.Pending && approvalPrev.Status != EPStatuses.Routed)
{
customApprove.Press();
}
}

 

Here is my Action Button:

        public PXAction<APInvoice> customApprove;
PXButton(CommitChanges = true, Category = Messages.ApprovalCategory, DisplayOnMainToolbar = true, IsLockedOnToolbar = true)]
PXUIField(DisplayName = EPMessages.CustomApprove, MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update, Enabled = true, Visible = false)]

protected virtual IEnumerable CustomApprove(PXAdapter adapter)
{
APInvoice document = Base.Document.Current;
EPApproval approval = Base.Approval.Current;

if (RoutingPanelDialogData.View.Answer == WebDialogResult.None)
{
if (approval != null)
{
RoutingPanelDialogData.Cache.Clear();
EPApproval_Extension approvalExt = approval.GetExtension<EPApproval_Extension>();
EPRoutingPanelDialogData dialogData = RoutingPanelDialogData.Cache.Insert() as EPRoutingPanelDialogData;

dialogData.ApprovalID = approval.ApprovalID;
dialogData.Reason = approval.Reason;
}
}

if (RoutingPanelDialogData.AskExt() != WebDialogResult.OK)
{
return adapter.Get();
}

// When OK button clicked should resume from here but when I trace doesnt hit this. Why?
EPRoutingPanelDialogData dialog = RoutingPanelDialogData.Current;

approval = PXSelect<EPApproval,
Where<EPApproval.approvalID, Equal<Required<EPApproval.approvalID>>>,
OrderBy<Asc<EPApproval.approvalID>>>
.Select(Base, dialog.ApprovalID).FirstOrDefault();

if (document != null && approval != null && dialog != null)
{
RouteDocument(document, approval, dialog, EPStatuses.Routed);
}

return adapter.Get();
}

 

Here is my Smart Panel:

  <px:PXSmartPanel runat="server" Width="600px" ID="RoutingPanelDialogDataSmartPanel" AllowResize="False" LoadOnDemand="True" CloseButtonDialogResult="Cancel" CaptionVisible="True" Caption="Routing Panel New" Key="RoutingPanelDialogData" AcceptButtonID="PXButtonOK" CancelButtonID="PXButtonCancel" AutoCallBack-Enabled="True" AutoCallBack-Command="Refresh" CallBackMode-CommitChanges="True" CallBackMode-PostData="Page">
<px:PXFormView runat="server" Caption="Routing Panel New" CaptionVisible="False" ID="RoutingPanelDialogDataFormView" DataSourceID="ds" DataMember="RoutingPanelDialogData">
<Template>
<px:PXLayoutRule runat="server" StartColumn="True" ID="RoutingPanelDialogDataLayoutRule" />
<px:PXPanel runat="server" RenderStyle="Simple" ID="RoutingPanelDialogDataPanelParams">
<px:PXLayoutRule runat="server" StartColumn="True" SuppressLabel="False" LabelsWidth="SM" ControlSize="M" ID="RoutingPanelDialogDataLayoutRuleParams" />
<px:PXNumberEdit runat="server" Enabled="False" Width="300" CommitChanges="True" DataField="ApprovalID" ID="edApprovalID" Visible="True" />
<px:PXTextEdit runat="server" TextMode="MultiLine" Enabled="True" Width="300" Height="150" CommitChanges="True" DataField="Reason" ID="edReason" Visible="True" /></px:PXPanel>
<px:PXPanel runat="server" SkinID="Buttons" ID="RoutingPanelDialogDataPanelButtons">
<px:PXButton runat="server" Text="OK" DialogResult="OK" CommandSourceID="ds" ID="PXButtonOK" />
<px:PXButton runat="server" Text="Cancel" DialogResult="Cancel" CommandSourceID="ds" ID="PXButtonCancel" /></px:PXPanel></Template></px:PXFormView></px:PXSmartPanel>

 

You don’t want to call an action from an event handler, especially if you are using the Ask method(or its variations). It will break the sequence of events and can cause erratic behavior. Event handlers also have specific error handling that can cause issues.

The ask method actually throws an error that the system then catches and displays the popup window. After the user interacts with it the system calls the same method except the call to Ask now returns the value from the user interaction.

If you use the Acuminator extension it will help catch things like this(https://github.com/Acumatica/Acuminator/blob/master/docs/diagnostics/PX1071.md)


Reply