Solved

Unreachable code problem

  • 30 October 2023
  • 2 replies
  • 38 views

Userlevel 2

Good day,

 

I have a custom field to indicate if a voided payment is type non-sufficient fund, if it is, when I press release in the voided payment, I have to create a debit memo and redirect from the payment and applications screen to the invoice and memos screen.

 

The problem is that if I try to redirect the screen, the voided payment does not release and does not save either, because the RedirectException interrups the process.

 

Do you have any idea how can I make the transition from one screen to another having the voided payment released?

 

invMemo.Actions.PressSave();

throw new PXRedirectRequiredException(invMemo, true, "Invoice");
                }
                
    return Base.release.Press(adapter);

 public virtual IEnumerable Release(PXAdapter adapter)
{

ARPayment row = Base.Document.Current;
ARRegisterExt rowExt = PXCache<ARRegister>.GetExtension<ARRegisterExt>(row);
var invMemo = PXGraph.CreateInstance<ARInvoiceEntry>();
//validating if voided payment should be Non-Sufficient fund.
if (rowExt.UsrNSF == true && Base.Document.Ask("Non-Sufficient Funds is checked, do you really want to release voided payment?",
MessageButtons.YesNo) != WebDialogResult.Yes)
{
return adapter.Get();
}
else
{
//If document type is a voided payment and NSF is checked create the Debit Memo.

if (row.DocType == ARDocType.VoidPayment && rowExt.UsrNSF == true)
{

var arPreferences = PXGraph.CreateInstance<ARSetupMaint>();
ARInvoice invoiceMemo = new ARInvoice();
ARTran tran = new ARTran();
ARSetup setup = PXSelect<ARSetup>.Select(Base);
invoiceMemo.DocType = ARDocType.DebitMemo;
invoiceMemo.CustomerID = row.CustomerID;
invoiceMemo.DocDate = row.DocDate;

invoiceMemo = invMemo.Document.Insert(invoiceMemo);

if (setup != null)
{
ARSetupExt setupExt = setup.GetExtension<ARSetupExt>();

if (setupExt != null)
{
string inventoryCD = setupExt.UsrNstk;
InventoryItem item = PXSelect<InventoryItem, Where<InventoryItem.inventoryCD, Equal<Required<InventoryItem.inventoryCD>>>>.Select(Base, inventoryCD);
InventoryItemCurySettings itemCury = PXSelect<InventoryItemCurySettings, Where<InventoryItemCurySettings.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(Base, item.InventoryID);

if (item != null && itemCury != null)
{
tran.InventoryID = item.InventoryID;
tran.Qty = 1;
tran.CuryUnitPrice = itemCury.BasePrice;
tran = invMemo.Transactions.Insert(tran);
}
}
}

invMemo.Actions.PressSave();
throw new PXRedirectRequiredException(invMemo, true, "Invoice");
}

return Base.release.Press(adapter);
}

}

 

icon

Best answer by RohitRattan88 30 October 2023, 20:39

View original

2 replies

Userlevel 2

@orlandonegron43 here’s the general direction you need to go:

Override the action using actionDelegat,

Call the basemethod

add custom code

Reference: How to override an action in a graph extension? | Community (acumatica.com)

baseMethod in Action Override Overrode is null | Community (acumatica.com)

Example:

public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);
[PXOverride]
public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
{
var res = baseMethod(adapter);

PXLongOperation.WaitCompletion(Base.UID);// i belive there is a long operatoin. if you wanna wait for long async operatoin to complete before proceesing
PXTrace.WriteInformation("TEst");

//custom validation and code....
throw new PXRedirectRequiredException(invMemo, true, "Invoice");

return adapter.Get();
}

 

My method is different, but it is basically from the concept of your example, thank you so much.

Userlevel 7
Badge +4

@orlandonegron43 here’s the general direction you need to go:

Override the action using actionDelegat,

Call the basemethod

add custom code

Reference: How to override an action in a graph extension? | Community (acumatica.com)

baseMethod in Action Override Overrode is null | Community (acumatica.com)

Example:

public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);
[PXOverride]
public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
{
var res = baseMethod(adapter);

PXLongOperation.WaitCompletion(Base.UID);// i belive there is a long operatoin. if you wanna wait for long async operatoin to complete before proceesing
PXTrace.WriteInformation("TEst");

//custom validation and code....
throw new PXRedirectRequiredException(invMemo, true, "Invoice");

return adapter.Get();
}

 

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved