Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

How to get the current employment start date of employee from employment history

(1) ShareShare
ReportReport
Posted on by 3,045

Hello Everyone,

I am creating RunBase class and exporting employee data in excel format. Requirement is at runtime we will provide 2 dates which is compared with Employment StartDate in Employment history form (HCMEmployment.ValidFrom). Employement Start date is the ValidTimeState field in the HCMEmployment table. 

Based on Users time zone the employment StartDate field value is changed but in DB it will store same value which we have entered.

e.g: if I am in India time zone and enter the value 31/12/2021 12:00:00 AM. When we change the user time zone to US or pacific zone it is changed to 01/01/2022 06:30:00 PM. In table field store the value " 31/12/2021 12:00:00 AM" this doesn't change.  

So, whenever we run the report in US time zone and select the date 01/01/2022 it is generating blank report because table store 31/12/2021. 

How can I handle this problem? 

Thanks.

  • Pooja Karki Profile Picture
    Pooja Karki 3,045 on at
    RE: How to get the current employment start date of employee from employment history

    It is done thanks.

  • Pooja Karki Profile Picture
    Pooja Karki 3,045 on at
    RE: How to get the current employment start date of employee from employment history

    It is in Usertimezone.

  • Parag Chapre Profile Picture
    Parag Chapre 12,271 Most Valuable Professional on at
    RE: How to get the current employment start date of employee from employment history

    Hi Pooja,

    Is value in the form based on usertimezone or companytimezone?

  • Pooja Karki Profile Picture
    Pooja Karki 3,045 on at
    RE: How to get the current employment start date of employee from employment history

    Sure, will do that.

    I just wanted to know if I want to print the changed date in report how I can do that?

    If I changed time zone and whatever value is coming in Form same needs to print in report.

  • Suggested answer
    Parag Chapre Profile Picture
    Parag Chapre 12,271 Most Valuable Professional on at
    RE: How to get the current employment start date of employee from employment history

    Hi Pooja, Can you please mark the answer as verified so that it can help others.

  • Suggested answer
    Pooja Karki Profile Picture
    Pooja Karki 3,045 on at
    RE: How to get the current employment start date of employee from employment history

    thanks for answer it works.

  • Verified answer
    Parag Chapre Profile Picture
    Parag Chapre 12,271 Most Valuable Professional on at
    RE: How to get the current employment start date of employee from employment history

    Hi Pooja,

    You need to write below code in your class.

    HcmEmployment hcmEmployment;
    ValidFromDateTime dateFrom = DateTimeUtil::minValue();
    ValidToDateTime dateTo = DateTimeUtil::maxValue();
    Timezone usertimezone = DateTimeUtil::getUserPreferredTimeZone();
    utcdatetime utcFieldTimeBeginOfDay = DateTimeUtil::newDateTime(DateTimeUtil::date(datetoValidate), 0, usertimezone);
    utcdatetime utcFieldTimeEndOfDay = DateTimeUtil::newDateTime(DateTimeUtil::date(dateToValidate), #secondsPerDay - 1, usertimezone); // 23:59:59 of the day

    In above case, you can use utcFieldTimeEndOfDay to get the value save in 23:59:59 format.

    Please try above code and get back to me.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,431 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,503 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans