New capability in X++ : The In operator

Hi Folks, 

Microsoft recently added a new feature in X++, making it easier to make certain SQL-where clauses extensible in X++. 


 Consider this method from CustomTrans>>calcPriceAmountStdAdjustment (Custom objects)

private PriceAmountStdAdjustment calcPriceAmountStdAdjustment()
{
        CustomSettlement customSettlement;

       
        select sum(PriceAmountAdjustment) from customSettlement
where customSettlement.TransRecId == this.RecId
&& customSettlement.Cancelled == NoYes::No
&& (customSettlement.OperationsPosting == PostingType::PurchStdProfit
|| customSettlement.OperationsPosting == PostingType::PurchStdLoss
|| customSettlement.OperationsPosting == PostingType::InventStdProfit
|| customSettlement.OperationsPosting == PostingType::InventStdLoss)
; return customSettlement.PriceAmountAdjustment;
}
It can now be refactored to support an extender in controlling which PostingTypes to include in the calculation:

private PriceAmountStdAdjustment calcPriceAmountStdAdjustment()
{ CustomSettlement customSettlement;
Container postingTypes = this. postingTypesForPriceAmtStdAdjustmentCalculation(); select sum(PriceAmountAdjustment) from customSettlement
where customSettlement.TransRecId == this.RecId
&& customSettlement.Cancelled == NoYes::No
&& (customSettlement.OperationsPosting in postingTypes ;
return customSettlement.PriceAmountAdjustment;
} protector container postingTypesForPriceAmtStdAdjustmentCalculation()
{ return    [PostingType::PurchStdProfit,
PostingType::PurchStdLoss,
PostingType::InventStdProfit,
PostingType::InventStdLoss];
}
Awesome feature but still most people didn't noticed.

No comments:

Post a Comment