X++ code to compare different dates and display the max value using SysComputedColumn in D365FO
Chaitanya Golla
17,225
Hi,
In this post we can view the code to compare different dates and display the max value using SysComputedColumn in D365FO.
Please refer to this post to know about the details of the view DAXPurchAgreementDetails.
( ) X code using SysComputedColumn with a SQL query in D365FO. - Dynamics 365 Finance Community
Step 1: Created a new field on the view DAXPurchAgreementDetails by name MaxTransitDate to display only the date value.
Step 2: Created a method "getMaxDate" to compare the dates ConfirmedDlv, DeliveryDate and LocalDeliveryDate of purchase order and display the max value.
public static server str getMaxDate()
{
TableName viewName = tableStr(DAXPurchAgreementDetails);
str confirmedDlv = SysComputedColumn::returnField(viewName, identifierStr(PurchTable), fieldStr(PurchTable, ConfirmedDlv));
str deliveryDate = SysComputedColumn::returnField(viewName, identifierStr(PurchTable), fieldStr(PurchTable, DeliveryDate));
str localDeliveryDate = SysComputedColumn::returnField(viewName, identifierStr(PurchTable), fieldStr(PurchTable, LocalDeliveryDate));
return SysComputedColumn::if(SysComputedColumn::compareExpressions(confirmedDlv, '>', deliveryDate),
SysComputedColumn::if(SysComputedColumn::compareExpressions(confirmedDlv, '>', localDeliveryDate),
confirmedDlv,
localDeliveryDate),
SysComputedColumn::if(SysComputedColumn::compareExpressions(deliveryDate, '>', localDeliveryDate),
deliveryDate,
localDeliveryDate));
}
Step 3: Assigned view method "getMaxDate" to the newly created field "MaxTransitDate".
Step 4: Build the solution. In the table browser able to see the max value of dates of purchase orders.
Output:
*This post is locked for comments