web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

X++ Query CreatedDateTime

(0) ShareShare
ReportReport
Posted on by 238

Hey,

I have simple requirements i need to select records created greater than X date. 

I am trying to do that via x query but i have a problem when i add a range value it becomes "1900-01-01T00:00:00"  but value was setting diffrent than that date.

There is how i trying to do: 

Query                           query;
QueryRun                        queryRun;
QueryBuildDataSource            qbdsPurch,qbdsPurchLine;
utcdatetime                     utcTime;
str                             timestr;



    query = new Query();
    qbdsPurch = query.addDataSource(tableNum(PurchTable));

    qbdsPurchLine = qbdsPurch.addDataSource(tableNum(PurchLine));
    qbdsPurchLine.joinMode(JoinMode::InnerJoin);
    qbdsPurchLine.addLink(fieldNum(PurchTable,PurchId),fieldNum(PurchLine, PurchId));
    qbdsPurchLine.addSortField(fieldNum(PurchLine,PurchId));    

    qbdsPurch.addRange(fieldNum(PurchTable,PurchaseType)).value(enum2Str(PurchaseType::Purch));
    qbdsPurch.addRange(fieldNum(PurchTable,PurchStatus)).value(enum2Str(PurchStatus::Backorder));
    

    utcTime = DateTimeUtil::getToday(TimeZone::GMTPLUS0300ISTANBUL);
    timestr = DateTimeUtil::toStr(utcTime);
    qbdsPurch.addRange(fieldNum(PurchTable,CreatedDateTime)).value(strfmt(" >= %1",timestr));

i am watching values on debug and utcTime value is {09/15/2022 00:00:00}

timeStr > "2022-09-15T00:00:00"

and qbdsPurch > {SELECT * FROM PurchTable(PurchTable_1) WHERE ((PurchaseType = 3)) AND ((PurchStatus = 1)) AND ((createdDateTime = '1900-01-01T00:00:00')) JOIN * FROM PurchLine(PurchLine_1) ORDER BY PurchLine.PurchId ASC ON PurchTable.PurchId = PurchLine.PurchId}

Why this createdDateTime becomes equal to null ? Any helps 

I have the same question (0)
  • Verified answer
    GirishS Profile Picture
    27,827 Moderator on at
    RE: X++ Query CreatedDateTime

    utcTime = DateTimeUtil::getToday(TimeZone::GMTPLUS0300ISTANBUL);
    qbdsPurch.addRange(fieldNum(PurchTable, CreatedDateTime)).value(queryRange(utcTime, DateTimeUtil::maxValue()));
    

    Hi Ferhat.S,

    Try the above code which will return data which is greater then X date.

    Thanks,

    Girish S.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
#ManoVerse Profile Picture

#ManoVerse 101

#2
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 66 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans