Solved

Long Running Operation does not show standard Popup Status

  • 7 December 2022
  • 4 replies
  • 143 views

Userlevel 3
Badge +1

I would like the standard status popup to show while a long running operation is executing. How do I go about this?

I thought placing the operation inside PXLongOperation.StartOperation(Base, delegate {...}); would do the trick but nothing changes.

 

Thanks 
         

icon

Best answer by Leif 7 December 2022, 21:56

View original

4 replies

Userlevel 7
Badge +17

Hi @Leif  Can you please share your code here.

Userlevel 3
Badge +1

Sure, its in progress so it still needs some work but I hope it helps.

Please note the PX1008 suppression

[PXLocalizable]
public sealed class ProjectEntry_Extension : PXGraphExtension<ProjectEntry>
{
public static bool IsActive() => (true);


public PXAction<PMProject> InvoiceAllowances;
[PXProcessButton]
[PXUIField(DisplayName = "Invoice Allowances")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Default", "PX1008:The reference to {0} is captured in the {1} delegate and will cause synchronous execution of the delegate. It may lead to random bugs and data consistency issues.", Justification = "<Pending>")]
protected IEnumerable invoiceAllowances(PXAdapter adapter)
{
Base.Save.Press();
int? projectID = Base.Project.Current.ContractID;
PXLongOperation.StartOperation(Base, delegate
{
ProjectEntry prjGraph = PXGraph.CreateInstance<ProjectEntry>();

PMProject prj = prjGraph.Project.Current = PMProject.PK.Find(prjGraph, projectID);
PMProject_Ext prjExt = prj.GetExtension<PMProject_Ext>();

var selectOrderItems = new SelectFrom<GPPMProjectOrderItem>.
Where<GPPMProjectOrderItem.projectOrderSetID.IsEqual<PMProject_Ext.usrCurrentOrderSetID.FromCurrent>
>.View(prjGraph);

var orderItems = new List<GPPMProjectOrderItem>(selectOrderItems.Select().RowCast<GPPMProjectOrderItem>());

var tasks = new List<PMTask>(prjGraph.Tasks.Select().RowCast<PMTask>());

foreach (var task in tasks)
{
if (task.CompletedPercent > 0)
{

PMTask_Ext taskEx = task.GetExtension<PMTask_Ext>();
List<GPPMProjectOrderItem> taskOrderItems;
taskOrderItems = getTaskOrderItems(prjGraph, task, orderItems);


if (taskEx.UsrAllowancesBatchNbr == null)
{
autoT_EnterAllowanceExpenseOffsets(prj, task, taskOrderItems);
}
}
}
prjGraph.Actions.PressSave();

});
return adapter.Get();
}
private static void autoT_EnterAllowanceExpenseOffsets(ProjectEntry prjGraph, PMProject prj, PMTask task, List<GPPMProjectOrderItem> taskOrderItems)
{


var GLTrans = new List<taskAllowanceGLTranPrams>();

var ExpenseOffset = "700";

var toolNetAllowance = taskOrderItems.FindAll(i => isToolCharge(i)).Sum(x => x.UnitCost * x.Quantity) ?? 0;
if (toolNetAllowance != 0)
GLTrans.Add(new taskAllowanceGLTranPrams() { amount = toolNetAllowance, description = "Tool Allowances", debitAccount = "508", creditAccount = ExpenseOffset });

var equipNetAllowance = taskOrderItems.FindAll(i => isEquipCharge(i)).Sum(x => x.UnitCost * x.Quantity) ?? 0;
if (equipNetAllowance != 0)
GLTrans.Add(new taskAllowanceGLTranPrams() { amount = equipNetAllowance, description = "Equipment Allowances", debitAccount = "506", creditAccount = ExpenseOffset });


var workNetAllowance = taskOrderItems.FindAll(i => isWork(i)).Sum(x => x.UnitCost * x.Quantity) ?? 0;
if (workNetAllowance != 0)
{
decimal laborMultipler = (decimal)(1 / 1.41321);
decimal burdenMultipler = 1 - laborMultipler;
workNetAllowance = workNetAllowance * burdenMultipler;
GLTrans.Add(new taskAllowanceGLTranPrams() { amount = workNetAllowance, description = "Burden Allowances", debitAccount = "510", creditAccount = ExpenseOffset });
}

var contingkNetAllowance = taskOrderItems.FindAll(i => isContingCharge(i)).Sum(x => x.UnitCost * x.Quantity) ?? 0;
if (contingkNetAllowance != 0)
GLTrans.Add(new taskAllowanceGLTranPrams() { amount = contingkNetAllowance, description = "Contingency Allowances", debitAccount = "512", creditAccount = ExpenseOffset });

var otherNetAllowance = taskOrderItems.FindAll(i => isOtherCharge(i)).Sum(x => x.UnitCost * x.Quantity) ?? 0;
if (otherNetAllowance != 0)
GLTrans.Add(new taskAllowanceGLTranPrams() { amount = otherNetAllowance, description = "Other Allowances", debitAccount = "514", creditAccount = ExpenseOffset });


var prjExt = (PMProject_Ext)prj.GetExtension<PMProject_Ext>();
var os = GPPMProjectOrderSet.PK.Find(prjGraph, (int)prjExt.UsrIntialOrderSetID);
var orderSet = os.Description ?? prjExt.UsrIntialOrderSetID.ToString() ?? "?";
var batchDescription = $"Generated Project Allowance Expenses. Project: {prj.ContractCD} Task: {task.TaskCD.Trim()} OS: {orderSet}";

if (GLTrans.Count > 0)
createJournalTransactionForAllowances(prjGraph, 3, batchDescription, prj, task, GLTrans);

}



#region GL Entry
private class taskAllowanceGLTranPrams
{
public string description { get; set; }
public string creditAccount { get; set; }
public int? creditAccountID { get; set; }
public string debitAccount { get; set; }
public int? debitAccountID { get; set; }
public decimal amount { get; set; }

}
private static void createJournalTransactionForAllowances(ProjectEntry prjGraph, int branch, string batchDescription, PMProject prj, PMTask task, List<taskAllowanceGLTranPrams> entries)
{
GL.JournalEntry glGraph = PXGraph.CreateInstance<GL.JournalEntry>();

var prj_Ext = (PMProject_Ext)prj.GetExtension<PMProject_Ext>();
var b = new Batch()
{
Description = batchDescription
};
b = glGraph.BatchModule.Insert(b);


var actsSelect = new SelectFrom<GL.Account>.Where<GL.Account.accountCD.IsEqual<@P.AsString>>.View(prjGraph);
var equipExp540Act = actsSelect.Select("540").TopFirst;
var equipAsset175Act = actsSelect.Select("175").TopFirst;

foreach (var e in entries)
{
if (e.creditAccountID == null)
e.creditAccountID = actsSelect.Select(e.creditAccount).TopFirst.AccountID;

if (e.debitAccountID == null)
e.debitAccountID = actsSelect.Select(e.debitAccount).TopFirst.AccountID;
}

foreach (var e in entries)
{
glGraph.GLTranModuleBatNbr.Insert(new GLTran()
{
BranchID = branch,
AccountID = e.debitAccountID,
TranDesc = e.description,
ProjectID = task.ProjectID,
TaskID = task.TaskID,
CuryDebitAmt = e.amount
});


glGraph.GLTranModuleBatNbr.Insert(new GLTran()
{
BranchID = branch,
AccountID = e.creditAccountID,
TranDesc = e.description,
//ProjectID = task.ProjectID,
//TaskID = task.TaskID,
CuryCreditAmt = e.amount
});
}


glGraph.Save.Press();

var tskExt = task.GetExtension<PMTask_Ext>();

tskExt.UsrAllowancesBatchNbr = glGraph.BatchModule.Current.BatchNbr;
prjGraph.Tasks.Update(task);

}
#endregion

 

Userlevel 3
Badge +1

I have also tried this with no luck.

 

  public PXAction<PMProject> InvoiceAllowances;
[PXProcessButton]
[PXUIField(DisplayName = "Invoice Allowances")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Default", "PX1008:The reference to {0} is captured in the {1} delegate and will cause synchronous execution of the delegate. It may lead to random bugs and data consistency issues.", Justification = "<Pending>")]
protected IEnumerable invoiceAllowances(PXAdapter adapter)
{

Base.Save.Press();
PXLongOperation.StartOperation(Base, delegate
{
System.Threading.Thread.Sleep(5000);
});
return adapter.Get();
}

 

Userlevel 3
Badge +1

I cleaned up my code, and it seems to be working. Not sure what the source of the issue was.

 

Leif 

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