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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Selecting a range of record from validTimeState

(0) ShareShare
ReportReport
Posted on by 451

Hi ,

I have to select the records from HcmEmployment table where the validFrom field should be greater than or equal to the fromDate  . I have written the below code but it is picking any record that is valid till toDate without checking the fromDate

fromDate = today();
toDate = today()+1;
legalEntity = 'gb01';

while select validTimeState(fromDate, toDate) hcmEmployment
    where hcmEmployment.LegalEntity == CompanyInfo::findDataArea(legalEntity).RecId
        join PersonnelNumber from hcmWorker where hcmWorker.RecId == hcmEmployment.Worker

{
info(strFmt("%1 ,%2,%3 ", hcmWorker.PersonnelNumber, DateTimeUtil::date(hcmEmployment.ValidFrom) ,
hcmEmployment.EmploymentType));
}

0638.Untitled.jpg

As you can see it is picking a record which has fromdate of 7/2/2017 and toDate till today .

*This post is locked for comments

I have the same question (0)
  • Basheer17 Profile Picture
    2,720 on at

    ValidTimeState(date1, date2) is used to query the records that are effective during a time period. Include ValidTo date in your info method to confirm. For example record with ValidFrom 02/01/2015 and ValidTo 05/12/2018 is a effective record for (07/21/2017, 07/28/2017) time period.

  • Dev Profile Picture
    451 on at

    but I want a records that start from and after fromDate till toDate i.e in my example all the records from hcmEmployment where validfrom which is today or tomorrow and validto till tomorrow

  • Basheer17 Profile Picture
    2,720 on at

    Well you can use (ValidFrom >= today && ValidTo <= tomorrow) but you have to consider this even if you don't use ValidTimeState(AsOfDate) in your select statement it will be appended implicitly for ValidTimeState tabels. So if you use above condition you will only get effective records which satisfies the conditions in where clause.

  • Suggested answer
    Ajit Profile Picture
    8,755 on at

    Still system will return the valid record (!Expired).

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 AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans