Friday, January 6, 2023

How to apply custom range on AOT query in D365 Finance and Operations

Hi All,
Here in this blog will see how to apply custom range on AOT query.

Requirement: Add range on AOT query to get the records created before given days (createdDateTime - PriorDays)

Steps 1 - Add new field in the parameters. Please refer below screen shot.



Step 2 - Create new class and use attribute for range method. Refer below screen shot.

internal final class TestQueryRangeUtil
{
    
    [QueryRangeFunctionAttribute()]
    public static str greaterThanDateByParameter()
    {
        int relativeDays = SalesParameters::find().TestPriorDays;
        utcdatetime  currentDateTime;

        currentDateTime = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(),               DateTimeUtil::getUserPreferredTimeZone());

        return '> ' +              SysQueryRangeUtil::value(DateTimeUtil::date(DateTimeUtil::addDays(currentDateTime,relativeDays)));  
    }

}
Step 3:Create range on AOT query and add below given expression as value.

(TESTQueryRangeUtil::greaterThanDateByParameter())








Thats it. Happy Coding.

No comments:

Post a Comment

Post partial packing slip in D365FO

How to Post a Partial Packing Slip in D365FO and AX 2012 How to Post a Partial Packing Slip in D365FO and AX 2012 Understanding t...