Skip to main content
Solved

How to use PXDefault to set default value for a new field?

  • 21 February 2022
  • 3 replies
  • 2909 views

Forum|alt.badge.img+1

Hi all,

I want to add a new field to the SO that the value is from the customer’s buying group. The buying group is under the Attributes. I tried to use PXDefault to search the attribute’s value. But I have a problem is I need to use fixed attribute ID. The value is not linked with the buying group value. I need to save the value to the database at that moment. Because the buying group value may changed later. Does any one knows how to do it ? Thanks. 

 

 

 

 

Best answer by Naveen Boga

Hi, @larryly Acumatica will not allow us to provide the static text on the PXDefault hence, we need to use the BQL constants. 

I have modified your DAC filed PXDefault code, it seems there are some wrong conditions added.

Please find the updated DAC filed code below.

BQL Constants Class

public class AZConstants
    { 
        public class BUYGROUP : PX.Data.BQL.BqlString.Constant<BUYGROUP>
        {
            public BUYGROUP() : base("BUYGROUP") { }
        } 
    }

 

DAC Field:

#region UsrBuyingGroup
        [PXDBString(50, IsUnicode = true)]
        [PXUIField(DisplayName = "Buying Group")]
        [PXDefault(typeof(Search2<CSAnswers.value, LeftJoin<BAccount,
                          On<BAccount.noteID, Equal<CSAnswers.refNoteID>,
                          And<BAccount.bAccountID, Equal<Current<SOOrder.customerID>>>>>,
                          Where<CSAnswers.attributeID, Equal<AZConstants.BUYGROUP>>>))]

        public virtual string UsrBuyingGroup { get; set; }
        public abstract class usrBuyingGroup : PX.Data.BQL.BqlString.Field<usrBuyingGroup> { }
        #endregion

 

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

3 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3381 replies
  • Answer
  • February 22, 2022

Hi, @larryly Acumatica will not allow us to provide the static text on the PXDefault hence, we need to use the BQL constants. 

I have modified your DAC filed PXDefault code, it seems there are some wrong conditions added.

Please find the updated DAC filed code below.

BQL Constants Class

public class AZConstants
    { 
        public class BUYGROUP : PX.Data.BQL.BqlString.Constant<BUYGROUP>
        {
            public BUYGROUP() : base("BUYGROUP") { }
        } 
    }

 

DAC Field:

#region UsrBuyingGroup
        [PXDBString(50, IsUnicode = true)]
        [PXUIField(DisplayName = "Buying Group")]
        [PXDefault(typeof(Search2<CSAnswers.value, LeftJoin<BAccount,
                          On<BAccount.noteID, Equal<CSAnswers.refNoteID>,
                          And<BAccount.bAccountID, Equal<Current<SOOrder.customerID>>>>>,
                          Where<CSAnswers.attributeID, Equal<AZConstants.BUYGROUP>>>))]

        public virtual string UsrBuyingGroup { get; set; }
        public abstract class usrBuyingGroup : PX.Data.BQL.BqlString.Field<usrBuyingGroup> { }
        #endregion

 


deebhane
Semi-Pro I
Forum|alt.badge.img+1
  • Semi-Pro I
  • 62 replies
  • February 22, 2022

Hi @larryly ,

In continuation @Naveen B  statement on assign a default value, if your looking for dynamic attribute name to fetch the stored values, we can customize the sales order / inventory preference and create a custom field as buying group Attribute ID as a configuration and list all the attributes for user to select the attribute that they would like to use as buying group. 

The modify the Sales order DAC to get the attribute ID from the  preference screen . 

 

#region UsrBuyingGroup

[PXDBString(50, IsUnicode = true)] [PXUIField(DisplayName = "Buying Group")] [PXDefault(typeof(Search2<CSAnswers.value, LeftJoin<BAccount, On<BAccount.noteID, Equal<CSAnswers.refNoteID>, And<BAccount.bAccountID, Equal<Current<SOOrder.customerID>>>>>, Where<CSAnswers.attributeID, Equal<SOSetup.UsrBuyinggroupID>>>))]

public virtual string UsrBuyingGroup { get; set; }

public abstract class usrBuyingGroup : PX.Data.BQL.BqlString.Field<usrBuyingGroup> { }

#endregion

 

Make sure on the Sales order graph preference screen DAC View is declared. 

 

 


Forum|alt.badge.img+1
  • Author
  • Semi-Pro II
  • 88 replies
  • March 3, 2022

@Naveen B Thanks for you code. I was realize I can’t use default value for the field. Because the customer may changed. So I add a event to fill the field value.

 

 @deebhane Thank you. It’s a great idea. I can use it on my other project.  


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