Skip to main content

Notifications

Announcements

No record found.

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 

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,321 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans