Solved

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

  • 21 February 2022
  • 3 replies
  • 2301 views

Userlevel 4
Badge +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. 

 

 

 

 

icon

Best answer by Naveen Boga 22 February 2022, 03:45

View original

3 replies

Userlevel 7
Badge +17

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

 

Userlevel 4
Badge +1

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. 

 

 

Userlevel 4
Badge +1

@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


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