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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Select with Timestamp (ValidDateTime)

(0) ShareShare
ReportReport
Posted on by 4,131

Hi,

If I have a start date time and end date time, would like to get the active HCMEmployment record during that date range in Query, how can I write it in X++?

Thanks,

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    István Orosz Profile Picture
    2,137 on at

    Hi,

    You can refer to : Valid Time State Tables and Date Effective Data usage at msdn.microsoft.com/.../gg861781.aspx.

    Your query should look something like this:


    select validTimeState(validFrom, validTo)  . . . 

    from HcmEmployment  . . .

    Kind Regards,

    István

  • Suggested answer
    Zain Bokhari Profile Picture
    3,208 Moderator on at

    You can simply google it, the first link gives you the answer.

    To quote the example from Microsoft Library.

    static void VtsJob1(Args _args)
    {
        // A VTS table in AX 2012.
        CustPackingSlipTransHistory xrec1;
        utcDateTime myDateFrom , myDateTo;
        anytype myAnytype = -1;
    
        myDateFrom = DateTimeUtil::utcNow();
        myDateTo = myDateFrom;
    
        SELECT 
            validTimeState(myDateFrom, myDateTo)
                *
            FROM xrec1;
    
        myAnytype = xrec1.getFieldValue("RecId");
        info(myAnytype);
    }


  • Yuji Profile Picture
    4,131 on at

    Thanks István,

    But I am using Query, QueryRun and QueryBuildRange, not pure X++ statement.

    thanks,

  • Suggested answer
    Zain Bokhari Profile Picture
    3,208 Moderator on at

    Here is how you can use Query with ValidTimeState tables. Microsoft library pages also gives you an example.

  • Basheer17 Profile Picture
    2,720 on at

    For better understanding of this framework, download the Whitepaper Using_Date_Effective_Patterns_AX2012.pdf from www.microsoft.com/.../details.aspx.

  • Verified answer
    István Orosz Profile Picture
    2,137 on at

    Hi,

    You can use a similar solution to this:

    qry = new Query();

    ....

    qry.validTimeStateDateTimeRange(validFrom, validTo);

    ....

    Regards,

    István

  • Hassan EL Alama Profile Picture
    55 on at

    Hi,

    Not forget validTimeStateUpdate :

    logisticsPostalAddressHeader_ds.validTimeStateUpdate(ValidTimeStateUpdate::Correction);

       logisticsPostalAddressHeader_ds.query().validTimeStateDateTimeRange(DateTimeUtil::minValue(), DateTimeUtil::maxValue());

    Regards

    Hassan

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Yuji,

    you can use SysQuery::Range(), below is the example code:

    TransDate dateFrom;
    TransDate dateTo;
    Query qry = new Query();
    QueryBuildDataSource qbds1;
    ;
    ...
    ...
    
    qbds1.addRange(fieldNum(myTable,myField)).value(SysQuery::Range(dateFrom, dateTo));


    Regards

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Basit Profile Picture

Basit 1

#1
GL-01081504-0 Profile Picture

GL-01081504-0 1

#1
Roya Profile Picture

Roya 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans