Skip to main content
Answer

Adding a virtual field to a DAC that calculates a value

  • August 20, 2025
  • 2 replies
  • 62 views

Forum|alt.badge.img+1

I’m trying to add a field to the ARTran DAC that isn’t stored in the database, and instead calculates a value based on another field in the ARTran DAC.  I’ve found lots of examples online, but they all reference returning True or False, and I think they also are leaving stuff out.  Google AI and ChatGPT are leaving stuff out too, probably because they’re only as smart as their source.

What I want to do is add a “Transaction Multiplier” field like what exists in various OE and IN DACs--a value of 1 means that the transaction has a positive effect (like an invoice) and a value of -1 has a negative effect (a credit memo).  In human readable terms, I think my tasks are:

  • Add a non database field to the DAC
  • Add code to tell the system that if ARTran.Trantype = “CRM”, return -1.  Otherwise return 1.  Ideally I’d do this as a Switch in case I have other Trantypes that I need to account for.

Focusing on what I know, I added the field to the DAC (using the Data Access section in the customization) as a non persistent field.  Published, no issues.

I’ve done list based DAC fields before, so again, to test with what I know, I added the following code (there’s a bunch of “using” statements above in the code file), which does work (since it’s an int, the default value in the results is always “A”, but it proves the code works):

namespace PX.Objects.AR
{

public class tpl_ARTranDACExt : PXCacheExtension<PX.Objects.AR.ARTran>
{

#region UsrtplTranMult
[PXInt]
[PXIntList(new int[] {0,1}, new string[] {"A", "B"})] /*This one works!*/

public virtual int UsrtplTranMult {get; set; }
public abstract class usrtplTranMult: PX.Data.BQL.BqlInt.Field<usrtplTranMult> {}
#endregion

}

}

I know I need to replace the PXIntList with something else, probably a PXFormula or PXDBScalar?  But I’ve tried a dozen variations of what I’ve found online and all of them error, usually with “Type Expected” or telling me that I’m missing commas.

Best answer by lairdtim

I waded into the ChatGPT water a little deeper and found my answer.  I took one of the recommended PXFormula code snippets (that I got from ChatGPT but it kept failing), put it in my code and then asked ChatGPT to troubleshoot it.  It found the issue.  So here’s my final code for this field (Constants are defined in another file):

    #region UsrtplTranMult
[PXInt]
[PXFormula(typeof(
Switch<
Case<Where<ARTran.tranType, Equal<Const_CMType>>, Const_CMMult,
Case<Where<ARTran.tranType, Equal<Const_INVType>>, Const_ARMult>>,
Const_ARMult
>))]
public virtual int? UsrtplTranMult { get; set; }
public abstract class usrtplTranMult : PX.Data.BQL.BqlInt.Field<usrtplTranMult> { }
#endregion

 

2 replies

Forum|alt.badge.img+1
  • Author
  • Semi-Pro I
  • Answer
  • August 20, 2025

I waded into the ChatGPT water a little deeper and found my answer.  I took one of the recommended PXFormula code snippets (that I got from ChatGPT but it kept failing), put it in my code and then asked ChatGPT to troubleshoot it.  It found the issue.  So here’s my final code for this field (Constants are defined in another file):

    #region UsrtplTranMult
[PXInt]
[PXFormula(typeof(
Switch<
Case<Where<ARTran.tranType, Equal<Const_CMType>>, Const_CMMult,
Case<Where<ARTran.tranType, Equal<Const_INVType>>, Const_ARMult>>,
Const_ARMult
>))]
public virtual int? UsrtplTranMult { get; set; }
public abstract class usrtplTranMult : PX.Data.BQL.BqlInt.Field<usrtplTranMult> { }
#endregion

 


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • August 20, 2025

Thank you for sharing your solution with the community ​@lairdtim!