Skip to main content
Solved

Customer define default Reason Code

  • November 3, 2021
  • 2 replies
  • 185 views

Forum|alt.badge.img

I have created one selector custom field in Customers screen and managed to grab Reason Code information using the code below:

public class BAccountExt : PXCacheExtension<PX.Objects.CR.BAccount>
  {
    #region UsrReasonCode
    [PXDBString(CS.ReasonCode.reasonCodeID.Length, IsUnicode = true)]
    [PXUIField(DisplayName="Reason Code")]
    [PXSelector(typeof(Search<CS.ReasonCode.reasonCodeID,
        Where<CS.ReasonCode.usage, Equal<ReasonCodeUsages.sales>,
            Or<ReasonCode.usage, Equal<ReasonCodeUsages.issue>>>>), 
            DescriptionField = typeof(ReasonCode.descr), CacheGlobal = true)]
    [PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
    public virtual string UsrReasonCode { get; set; }
    public abstract class usrReasonCode : PX.Data.BQL.BqlString.Field<usrReasonCode> { }
    #endregion
  }
}

 

How can I grab the value set in the Customers screen and make it a default value in Sales Order screen. I have tried replacing the Reason Code field with the code below but failed to get the desired result:

[PXDBString(CS.ReasonCode.reasonCodeID.Length, IsUnicode = true)]
[PXSelector(typeof(Search<ReasonCode.reasonCodeID,
    Where<Current<SOLine.tranType>, Equal<INTranType.transfer>, And<ReasonCode.usage,
        Equal<ReasonCodeUsages.transfer>,
        Or<Current<SOLine.tranType>, NotEqual<INTranType.transfer>, And<ReasonCode.usage,
        In3<ReasonCodeUsages.sales, ReasonCodeUsages.issue>>>>>>), DescriptionField = typeof(ReasonCode.descr))]
[PXDefault(typeof(BAccountExt.usrReasonCode), PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIField(DisplayName = "Reason Code")]

 

Best answer by EGolshtein67

Hi there,

Please try the code below:

[PXDefault(typeof(Search<BAccountExt.usrReasonCode, Where<BAccount.bAccountID, Equal<Current<SOOrder.customerID>>>)

 

As per help article:

You usually set the default value to a DAC field by using the PXDefault attribute. You can set a constant as the default value or provide a BQL query to obtain a value from the database or data records from the cache. The default value is assigned to the field when a data record that includes this field is inserted into the cache.

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

2 replies

  • Jr Varsity I
  • 8 replies
  • Answer
  • November 3, 2021

Hi there,

Please try the code below:

[PXDefault(typeof(Search<BAccountExt.usrReasonCode, Where<BAccount.bAccountID, Equal<Current<SOOrder.customerID>>>)

 

As per help article:

You usually set the default value to a DAC field by using the PXDefault attribute. You can set a constant as the default value or provide a BQL query to obtain a value from the database or data records from the cache. The default value is assigned to the field when a data record that includes this field is inserted into the cache.


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 49 replies
  • November 5, 2021

Hi @EGolshtein67 , the query works as a charm. I missed out on querying the PXDefault part there.Thanks a lot!


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