Solved

PMTask Delete Causes "Collection was modified" Exception

  • 9 February 2023
  • 2 replies
  • 113 views

Userlevel 3
Badge +1

Hello,

 

I have added two views to the PMTaskEntry, all works except when I try and delete the PMTask via the UI. I get the following exception.

Collection was modified; enumeration operation may not execute.

at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at PX.Web.UI.PXCallbackManager.GetCallbackResultInternal(PXCallbackResultMethod resultMethod)

I think it has to do with the views trying to refresh while the row is being deleted, but I am not sure.

I appreciate the help, thanks in advance.

    public class PMTaskEntry_Ext : PXGraphExtension<PX.Objects.PM.ProjectTaskEntry>
{
public static bool IsActive() => (true);
#region Cost Budget

//[PXFilterable(new Type[] { })]
[PXDependToCache(typeof(PMTask))]
public PXSelect<PMCostBudget,
Where<PMCostBudget.projectID, Equal<Current<PMTask.projectID>>,
And<PMCostBudget.type, Equal<AccountType.expense>>>> CostBudget;


public IEnumerable costBudget()
{
var IsCostGroupByTask = false;

var pXSelect =
new PXSelect<PMCostBudget,
Where<PMCostBudget.projectID, Equal<Current<PMTask.projectID>>,
And<PMCostBudget.type, Equal<AccountType.expense>,
And<PMCostBudget.projectTaskID, Equal<Current<PMTask.taskID>>>
//And<Where<Current<PMTask.taskID>, IsNull,
//Or<Current<PMTask.taskID>, Equal<PMCostBudget.projectTaskID>>>>

>>,
OrderBy<Asc<PMCostBudget.projectID,
Asc<PMCostBudget.projectTaskID,
Asc<PMCostBudget.inventoryID,
Asc<PMCostBudget.costCodeID,
Asc<PMCostBudget.accountGroupID>>>>>>>(Base);

PXDelegateResult pXDelegateResult = new PXDelegateResult();
pXDelegateResult.Capacity = 202;
pXDelegateResult.IsResultFiltered = false;
pXDelegateResult.IsResultSorted = true;
pXDelegateResult.IsResultTruncated = false;
if (IsCostGroupByTask)
{
//List<PMCostBudget> list = new List<PMCostBudget>(pXSelect.Select().RowCast<PMCostBudget>());
//pXDelegateResult.AddRange(AggregateBudget(list));
}
else
{
PXView pXView = new PXView(Base, isReadOnly: false, pXSelect.View.BqlSelect);
int startRow = PXView.StartRow;
int totalRows = 0;
List<object> resultSet = pXView.Select(PXView.Currents, PXView.Parameters, PXView.Searches, PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRows);
PXView.StartRow = 0;
pXDelegateResult.AddRange(resultSet.RowCast<PMCostBudget>());
}

return pXDelegateResult;
}

#endregion

#region Transactions

public PXSetup<PMAccountGroup>.Where<BqlOperand<PMAccountGroup.groupCD, IBqlString>.IsEqual<GPConstants.PMAccountGroup_Labor>> laborAccountGroup;
public PXSetup<PMAccountGroup>.Where<BqlOperand<PMAccountGroup.groupCD, IBqlString>.IsEqual<GPConstants.PMAccountGroup_Sub>> subAccountGroup;
public PXSetup<PMAccountGroup>.Where<BqlOperand<PMAccountGroup.groupCD, IBqlString>.IsEqual<GPConstants.PMAccountGroup_Material>> materialAccountGroup;

[PXDependToCache(typeof(PMTask))]
public PXSelectJoin<PMTran, LeftJoin<PMRegister, On<PMTran.tranType, Equal<PMRegister.module>, And<PMTran.refNbr, Equal<PMRegister.refNbr>>>>, Where<PMTran.projectID, Equal<Current<PMTask.projectID>>>> LaborTransactions;
[PXDependToCache(typeof(PMTask))]
public PXSelectJoin<PMTran, LeftJoin<PMRegister, On<PMTran.tranType, Equal<PMRegister.module>, And<PMTran.refNbr, Equal<PMRegister.refNbr>>>>, Where<PMTran.projectID, Equal<Current<PMTask.projectID>>>> SubTransactions;
[PXDependToCache(typeof(PMTask))]
public PXSelectJoin<PMTran, LeftJoin<PMRegister, On<PMTran.tranType, Equal<PMRegister.module>, And<PMTran.refNbr, Equal<PMRegister.refNbr>>>>, Where<PMTran.projectID, Equal<Current<PMTask.projectID>>>> MaterialTransactions;
public virtual IEnumerable laborTransactions()
{
var t = Base.Task.Current;
if (laborAccountGroup != null)
{
PMAccountGroup act = laborAccountGroup.Select();
if (act != null)
{
return getTransactions(act.GroupID);
}
}
return Enumerable.Empty<PMTran>();
}
public virtual IEnumerable subTransactions()
{
if (subAccountGroup != null)
{
PMAccountGroup act = subAccountGroup.Select();
if (act != null)
{
return getTransactions(act.GroupID);
}
}
return Enumerable.Empty<PMTran>();
}
public virtual IEnumerable materialTransactions()
{
if (materialAccountGroup != null)
{
PMAccountGroup act = materialAccountGroup.Select();
if (act != null)
{
return getTransactions(act.GroupID); ;
}
}
return Enumerable.Empty<PMTran>();
}




public virtual IEnumerable getTransactions(int? accountGroupID)
{
List<object> list = new List<object>();
PXSelectBase<PMTran> pXSelectBase = new PXSelectJoin<PMTran,
LeftJoin<PMRegister, On<PMTran.tranType, Equal<PMRegister.module>, And<PMTran.refNbr, Equal<PMRegister.refNbr>>>,
LeftJoin<BAccount, On<BAccount.bAccountID, Equal<PMTran.resourceID>>,
LeftJoin<PMAccountGroup, On<PMAccountGroup.groupID, Equal<PMTran.accountGroupID>>,
LeftJoin<RegisterReleaseProcess.OffsetPMAccountGroup, On<RegisterReleaseProcess.OffsetPMAccountGroup.groupID, Equal<PMTran.offsetAccountGroupID>>>>>>,//>,
Where<True, Equal<True>, And2<Where<RegisterReleaseProcess.OffsetPMAccountGroup.groupID, IsNull,
Or<Match<RegisterReleaseProcess.OffsetPMAccountGroup, Current<AccessInfo.userName>>>>,
And<Where<PMAccountGroup.groupID, IsNull,
Or<Match<PMAccountGroup, Current<AccessInfo.userName>>>>>>>>(Base);


pXSelectBase.WhereAnd<Where<PMTran.projectID, Equal<Current<PMTask.projectID>>>>();

if (accountGroupID != null)
{
pXSelectBase.WhereAnd<Where<PMTran.accountGroupID, Equal<Required<PMTran.accountGroupID>>, Or<PMTran.offsetAccountGroupID, Equal<Required<PMTran.accountGroupID>>>>>();
list.Add(accountGroupID);
list.Add(accountGroupID);
}

pXSelectBase.WhereAnd<Where<PMTran.taskID, Equal<Current<PMTask.taskID>>>>();


return TimeCardMaint.QSelect(Base, pXSelectBase.View.BqlSelect, list.ToArray());
}
}

 

icon

Best answer by Leif 9 February 2023, 04:51

View original

2 replies

Userlevel 3
Badge +1

Never mind, the error is due to the fact that the task is associated with a PMCostBudget in the project. Once the cost budget is removed the task can be deleted.

Userlevel 7
Badge

Thank you for sharing your solution with the community @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