Skip to main content
Answer

Customer define default Reason Code

  • November 3, 2021
  • 2 replies
  • 218 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.

2 replies

  • Jr Varsity I
  • 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
  • Varsity I
  • November 5, 2021

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