Example of a complex X++ select statement and use of the orig() function
This method checks the if custom control added to the delivery term is set to yes or no.
If it's set to no, it should perform the standard logic. If it's set to yes, it should run the custom logic below.
public void checkTaxGroup()
{
DlvTerm dlvTermLocal = DlvTerm::find(this.DlvTerm);
if(dlvTermLocal.GSOGroupTaxYesNo == NoYes::Yes)
{
LogisticsLocationExt logisticsLocationExt;
LogisticsLocation logisticsLocation;
InventLocationLogisticsLocation inventLocationLogisticsLocation;
InventLocation inventLocation;
InventDim inventDim;
select TaxGroup from logisticsLocationExt
join logisticsLocation
join inventLocationLogisticsLocation
join inventLocation
join inventDim
where
logisticsLocationExt.Location == logisticsLocation.RecId &&
logisticsLocation.RecId == inventLocationLogisticsLocation.Location &&
(inventLocationLogisticsLocation.InventLocation == inventLocation.RecId &&
inventLocationLogisticsLocation.IsPrimary == NoYes::Yes) &&
inventLocation.InventLocationId == inventDim.InventLocationId &&
inventDim.InventDimId == this.InventDimId;
this.TaxGroup = logisticsLocationExt.TaxGroup;
}
}
For the orig() example, in this case I had to check if the Delivery Terms or Warehouse fields had changed:
if(this.DlvTerm != this.orig().DlvTerm)
{
if(this.inventDim().inventLocationId != this.orig().inventDim().inventLocationId)
{
this.checkTaxGroup();
}
}