Question

Warnings are lost once an exception is thrown

  • 29 November 2023
  • 0 replies
  • 46 views

Hi,

My requirement is to catch the warning raised by Acumatica on the Purchase Order Screen for Order Total field. If there is a warning message regarding budget exceeded, I need to convert it to an error and stop the Release From Hold Action.

I implemented the code but it works only one time the button is clicked, the next time the button is clicked, since the warnings from Acumatica are gone, the code does not work.

Steps:

  1. On Page load, there is a warning on the field Order total (The project budget is exceeded. For details, check warnings in the document lines.)
  2. Click Release from Hold button, error message is shown and the field is highlighted - Working as expected. Warning messages are lost because I raised exception.
  3. Click Release from Hold again, I am able to proceed since the Acumatica Warnings are not there after step 2.

Is it possible to retain the warnings as well as shown a message to the user at same time?

public bool IsBudgetExceeded { get; set; } = false;

public delegate IEnumerable ReleaseFromHoldDelegate(PXAdapter adapter);

[PXOverride]
public virtual IEnumerable ReleaseFromHold(PXAdapter adapter, ReleaseFromHoldDelegate baseMethod)
{
if (Base.Document.Current != null)
{
// Check If there is any Allocation Rule in progress
bool isAllocationTaskPrgress = IsAllocationTaskInProgress();
PXTrace.WriteInformation("isAllocationTaskPrgress:" + isAllocationTaskPrgress);
if (isAllocationTaskPrgress)
{
// Check If Budget is exceeded
bool isBudgetExceeded = CheckBudgetisExceeded();
PXTrace.WriteInformation("isBudgetExceeded:" + isBudgetExceeded);
if (isBudgetExceeded)
{
Base.Document.Cache.RaiseExceptionHandling<POOrder.curyOrderTotal>(Base.Document.Current, Base.Document.Current.CuryOrderTotal,
new PXSetPropertyException(PX.Objects.PM.Messages.BudgetControlDocumentWarning, PXErrorLevel.Warning));
throw new PXException(PX.Objects.PM.Messages.BudgetControlDocumentWarning);
}
}
}
return adapter.Get<POOrder>();
}

public void POOrder_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e, PXRowUpdated del)
{
del?.Invoke(sender, e);
if (e.Row == null)
return;

string warning = PXUIFieldAttribute.GetWarning<POOrder.curyOrderTotal>(sender, e.Row);

if (!string.IsNullOrEmpty(warning)
&& warning.Contains(PX.Objects.PM.Messages.BudgetControlDocumentWarning))
{
IsBudgetExceeded = true;
}
else
{
IsBudgetExceeded = false;
}
}
public void POOrder_curyOrderTotal_FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e, PXFieldSelecting del)
{
del?.Invoke(sender, e);
if (e.Row == null)
return;

string warning = PXUIFieldAttribute.GetWarning<POOrder.orderQty>(sender, e.Row);

if (!string.IsNullOrEmpty(warning)
&& warning.Contains(PX.Objects.PM.Messages.BudgetControlDocumentWarning))
{
IsBudgetExceeded = true;
}
else
{
IsBudgetExceeded = false;
}
}

private bool IsAllocationTaskInProgress()
{
bool isAllocationTaskPrgress;
var projectId = Base.Document.Current.ProjectID;
PXTrace.WriteInformation("projectId:" + projectId);
PXSelectBase<PMTask> selectTasks = new PXSelect<PMTask, Where<PMTask.projectID, Equal<Required<PMTask.projectID>>, And<PMTask.allocationID, IsNotNull>>>(Base);

List<PMTask> tasks = new List<PMTask>();
foreach (PMTask pmTask in selectTasks.Select(projectId))
{
tasks.Add(pmTask);
}
isAllocationTaskPrgress = tasks.Where(s => ApplicableAllocationRules.Contains(s.AllocationID.ToUpper())).Any();
return isAllocationTaskPrgress;
}

private bool CheckBudgetisExceeded()
{
return IsBudgetExceeded;
}

 


0 replies

Be the first to reply!

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