I have read through several posts here but am still have a problem trying to put the sum of a column from multiple rows of a grid into a header column. I have seen code snippets, however, I think I am not arranging my code correctly.
I am still very new to Acumatica coding.
Below the error message is the full CS code I am using. Everything validates and compiles, but when I try to access the Cases screen I receive this error message. So I obviously do not know where and what I need to do here.
Can someone point me in the correct direction?
What I am trying to do is on the Cases screen, use the Relations tab to associate Invoices to a Case and then in a new grid populate that grid with all of the invoice information from the Relations tab. (the other problem I have is that the new grid called “CAM Relations” only lists one invoice at a time, but that is a different problem not for this topic; unless dear reader you know what I am doing wrong there also).
Then I have a UDF in the header which I am trying to populate a grand total of all of the CuryLineTotal column entries in the header column. Screen shot of the header below as well.
Thank you!
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using PX.Common;
using PX.Data;
using System.Collections;
using PX.Data.EP;
using PX.Objects.AR;
using PX.Objects.CT;
using PX.Objects.CR.Workflows;
using PX.Objects.GL;
using PX.Objects.EP;
using PX.Objects.IN;
using PX.Objects.PM;
using PX.SM;
using PX.TM;
using PX.Objects;
using PX.Objects.CR;
using System.Net.Http;
using System.Collections.Generic;
using System.Collections;
namespace PX.Objects.CR
{
public class CRCaseMaint_Extension : PXGraphExtension<CRCaseMaint>
{
#region Event Handlers
protected virtual void CRCase_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected InvokeBaseHandler)
{
InvokeBaseHandler?.Invoke(cache, e);
var row = (CRCase)e.Row;
if (row != null)
{
if (row.CaseClassID == "CAM")
{
PXUIFieldAttribute.SetVisible<Objects.CR.CRCaseExt.usrRMAReason>(cache, row, false);
PXUIFieldAttribute.SetVisible<Objects.CR.CRCaseExt.usrSupportCategory >(cache, row, false);
PXUIFieldAttribute.SetVisible<Objects.CR.CRCaseExt.usrContractDesc>(cache, row, false);
PXUIFieldAttribute.SetVisible<Objects.CR.CRCaseExt.usrCaseStage>(cache, row, false);
PXUIFieldAttribute.SetVisible<Objects.CR.CRCaseExt.usrIGAHEquipmentID>(cache, row, false);
PXUIFieldAttribute.SetVisible<Objects.CR.CRCaseExt.usrInvoicesTotal>(cache, row, true);
}
}
}
protected virtual void CRCaseMaint_UsrInvoicesTotal_FieldSelecting(PXCache sender,PXFieldSelectingEventArgs e, PXFieldSelecting InvokeBaseHandler)
{
InvokeBaseHandler?.Invoke(sender, e);
CRCase row = (CRCase)e.Row;
if (row == null) return;
decimal? UsrInvoicesTotal = this.CAMRelationsView.Select().FirstTableItems.ToList().Select(x => x.CuryLineTotal).Sum();
e.ReturnValue UsrInvoicesTotal;
}
#endregion
}
// Following view declaration populates the new CAMInfo grid with ARInvoice information
#region Selects public PXSelect<ARInvoice, Where<ARInvoice.noteID, Equal<CurrentValue<CRRelation.targetNoteID>>>> CAMRelationsView;
#endregion
}