Skip to main content
Solved

Applying addition of fields


Forum|alt.badge.img+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.
 

Best answer by Vignesh Ponnusamy

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,

 

View original
Did this topic help you find an answer to your question?

7 replies

Forum|alt.badge.img+10
  • Semi-Pro III
  • 229 replies
  • October 27, 2023

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
 


Forum|alt.badge.img+3
  • Author
  • Captain II
  • 317 replies
  • October 27, 2023
sweta68 wrote:

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:
 

 


Forum|alt.badge.img+10
  • Semi-Pro III
  • 229 replies
  • October 27, 2023

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


Forum|alt.badge.img+3
  • Author
  • Captain II
  • 317 replies
  • October 27, 2023
sweta68 wrote:

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.


Forum|alt.badge.img+3
  • Author
  • Captain II
  • 317 replies
  • October 27, 2023

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


Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

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,

 


Forum|alt.badge.img+3
  • Author
  • Captain II
  • 317 replies
  • October 28, 2023
Vignesh Ponnusamy wrote:

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings