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.