D365FO – Creating Query Build Range on CreatedDateTime field

 

Example below explains how to create a QueryBuildRange on default field CreatedDateTime.

utcDateTime fromDateSelection, toDateSelection;
QueryBuildDataSource qbdsSalesLine = qbds.addDataSource(tablenum(SalesLine));
QueryBuildRange qbr_date = qbdsSalesLine.addRange(fieldnum(SalesLine,CreatedDateTime));

fromDateSelection = datetobeginUtcDateTime('Your From Date Filter', DateTimeUtil::getUserPreferredTimeZone());
toDateSelection = datetoendUtcDateTime('Your To Date Filter', DateTimeUtil::getUserPreferredTimeZone());

qbr_date.value(queryRange(fromDateSelection, toDateSelection));

Comments