Solved

Applying addition of fields

  • 27 October 2023
  • 7 replies
  • 100 views

Userlevel 6
Badge +3

hello Community,
i have been trying to create a new field and apply the summation logic for the particular field in the Subcontracts screen. What I have done till now is:
Created 3 new fields: A, B & C where C=A+B.

I have created a DAC Extension for Objects.PO.POOrder:
 


And Applied the below code:
using CRLocation = PX.Objects.CR.Standalone.Location;
using PX.Common;
using PX.Data.ReferentialIntegrity.Attributes;
using PX.Data.WorkflowAPI;
using PX.Data;
using PX.Objects.AP;
using PX.Objects.CM.Extensions;
using PX.Objects.CN.Subcontracts.SC.Graphs;
using PX.Objects.Common.Bql;
using PX.Objects.Common;
using PX.Objects.CR;
using PX.Objects.CS;
using PX.Objects.EP;
using PX.Objects.IN;
using PX.Objects.PM;
using PX.Objects.PO;
using PX.Objects;
using PX.SM;
using PX.TM;
using System.Collections.Generic;
using System.Web.Configuration;
using System;

namespace Addition
{
  public class POOrderExt : PXCacheExtension<PX.Objects.PO.POOrder>
  {
    #region UsrA
    [PXDBDecimal]
    [PXUIField(DisplayName="A")]
    public virtual decimal? UsrA { get; set; }
    #endregion
    
    #region UsrB
    [PXDBDecimal]
    [PXUIField(DisplayName="B")]
    public virtual decimal? UsrB { get; set; }
    #endregion
      
      #region UsrC
    [PXDBDecimal]
    [PXUIField(DisplayName="C")]
      [PXFormula(typeof(Add<usrA, usrB>))]
      public virtual decimal? UsrC { get; set; }
        public abstract class usrC : PX.Data.BQL.BqlDecimal.Field<usrC> { }
    #endregion
  }
}

What is it that I am missing here or not doing correctly?
Thanks.
 

icon

Best answer by Vignesh Ponnusamy 27 October 2023, 15:11

View original

7 replies

Userlevel 7
Badge +10

Hi @Harshita,

The PXFormula attribute should reference the fields using their name,

[PXFormula(typeof(Add<POOrderExt.usrA, POOrderExt.usrB>))]

You have missed the below code snippet for the usrA and usrB

 public abstract class usrA : PX.Data.BQL.BqlDecimal.Field<usrA> { }
public abstract class usrB : PX.Data.BQL.BqlDecimal.Field<usrB> { }



Here's the corrected code for your DAC extension:

namespace Addition
{
public class POOrderExt : PXCacheExtension<PX.Objects.PO.POOrder>
{
#region UsrA
[PXDBDecimal]
[PXUIField(DisplayName = "A")]
public virtual decimal? UsrA { get; set; }
public abstract class usrA : PX.Data.BQL.BqlDecimal.Field<usrA> { }
#endregion

#region UsrB
[PXDBDecimal]
[PXUIField(DisplayName = "B")]
public virtual decimal? UsrB { get; set; }
public abstract class usrB : PX.Data.BQL.BqlDecimal.Field<usrB> { }
#endregion

#region UsrC
[PXDBDecimal]
[PXUIField(DisplayName = "C")]
[PXFormula(typeof(Add<POOrderExt.usrA, POOrderExt.usrB>))]
public virtual decimal? UsrC { get; set; }
public abstract class usrC : PX.Data.BQL.BqlDecimal.Field<usrC> { }
#endregion
}
}

Hope it helps.!

 

Regards,

Sweta
 

Userlevel 6
Badge +3

Hi @Harshita,

The PXFormula attribute should reference the fields using their name,

[PXFormula(typeof(Add<POOrderExt.usrA, POOrderExt.usrB>))]

You have missed the below code snippet for the usrA and usrB

 public abstract class usrA : PX.Data.BQL.BqlDecimal.Field<usrA> { }
public abstract class usrB : PX.Data.BQL.BqlDecimal.Field<usrB> { }



Here's the corrected code for your DAC extension:

namespace Addition
{
public class POOrderExt : PXCacheExtension<PX.Objects.PO.POOrder>
{
#region UsrA
[PXDBDecimal]
[PXUIField(DisplayName = "A")]
public virtual decimal? UsrA { get; set; }
public abstract class usrA : PX.Data.BQL.BqlDecimal.Field<usrA> { }
#endregion

#region UsrB
[PXDBDecimal]
[PXUIField(DisplayName = "B")]
public virtual decimal? UsrB { get; set; }
public abstract class usrB : PX.Data.BQL.BqlDecimal.Field<usrB> { }
#endregion

#region UsrC
[PXDBDecimal]
[PXUIField(DisplayName = "C")]
[PXFormula(typeof(Add<POOrderExt.usrA, POOrderExt.usrB>))]
public virtual decimal? UsrC { get; set; }
public abstract class usrC : PX.Data.BQL.BqlDecimal.Field<usrC> { }
#endregion
}
}

Hope it helps.!

 

Regards,

Sweta
 

Hello @sweta68 , thanks for your prompt response. It got published successfully, but the field is not able to add and display the sum:
 

 

Userlevel 7
Badge +10

Hi @Harshita ,

The above code calculate field  automatically update whenever the values of usrA or usrB change. It's a way to create virtual fields that display computed values based on other fields in the DAC.


Make sure you have updated the value of usrA and usrB fields and try to save.

 

Regards,

Sweta

Userlevel 6
Badge +3

Hi @Harshita ,

The above code calculate field  automatically update whenever the values of usrA or usrB change. It's a way to create virtual fields that display computed values based on other fields in the DAC.


Make sure you have updated the value of usrA and usrB fields and try to save.

 

Regards,

Sweta

Yes I tried to modify the values in fields A & b and then saved the record. But it doesn’t display the sum.

Userlevel 6
Badge +3

Attached here is the pkg. I checked this out in other instance too, but sill the same.

Userlevel 7
Badge +4

Hi @Harshita,

I see you have declared two the DAC extension(one which has the formula), you can remove the extension mentioned below to fix the issue,

 

Userlevel 6
Badge +3

Hi @Harshita,

I see you have declared two the DAC extension(one which has the formula), you can remove the extension mentioned below to fix the issue,

 

Thanks a lot @Vignesh Ponnusamy , now it is reflecting as per the requirement. And thanks a lot @sweta68 , for guiding me out.

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