Skip to main content

Notifications

Dynamics 365 general forum
Answered

X++ Query CreatedDateTime

Posted on by 231

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 

  • Verified answer
    GirishS Profile Picture
    GirishS 27,828 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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,493 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans