Solved

sum of column in grid not updating the header column

  • 18 April 2023
  • 4 replies
  • 102 views

Userlevel 4
Badge

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

}

 

 

icon

Best answer by Naveen Boga 19 April 2023, 05:59

View original

4 replies

Userlevel 7
Badge +17

Hi @jeffgrammer69  I see there is an issue with your event code, which is hilighlighted in the RED color.

It should be CRCase instead CRCaseMaint.

 

        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;  
        }

 

Hope this solves your issue.

Userlevel 4
Badge

@Naveen Boga Thank you!  That almost worked.  I had to move it out of the EventHandler region and into its own region as shown below; but even then it did not total all of the invoices that were listed in the Relations tab item.  Only the one I had highlighted/selected.

Perhaps I need to solve the problem first of fully populating the CAM Document Info tab with all of the invoices first? (link to that other topic is below the code snippet)

    #region InvoiceTotals
      protected virtual void CRCase_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

Populate grid from another grid

Userlevel 7
Badge +17

Hi @jeffgrammer69  Great! that actual reported issue is closed.

Now, we need to work with the logic to populate the sum, for this can you please share the customization project, so that I can take a look and help you if I found anything?

Badge +11

          decimal? UsrInvoicesTotal = this.CAMRelationsView.Select().FirstTableItems.ToList().Select(x => x.CuryLineTotal).Sum();
        e.ReturnValue = UsrInvoicesTotal;
      }  
    #endregion

This line strikes me as being odd. I’m not positive this is your problem, but I would write that like this:

decimal? invoicesTotal = this.CAMRelationsView.Select().FirstTableItems.Sum(x => x.CuryLineTotal);

e.ReturnValue = invoicesTotal;

 

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