Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Calculate and populate school grade from date of birth

(0) ShareShare
ReportReport
Posted on by 15

I can calculate a contact's age from their date of birth, but I would now like to calculate their school year.

In this country the new school year starts on April 2nd and the students' age on that date determines their school grade/year.

So firstly, I need to calculate their age on April 2nd of the current year.

I then need to link this to their school grade i.e. 'if age 13 on April 2nd of current year' automatically populates another field with 'Junior High School Grade 2'

Any help with formulas for Dynamics 365 would be appreciated.

  • Community member Profile Picture
    Community member 12 on at
    Calculate and populate school grade from date of birth
    brilliant solution! Converting birth dates to school grades is an innovative approach that simplifies academic records. But if you pay for essay at RoyalWriter.co.uk then it deserves praise. As a satisfied user, I appreciate their expertise and commitment to excellence. The seamless integration of technology and education is truly remarkable. Thank you RoyalWriter.co.uk for consistently providing quality services.
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Calculate and populate school grade from date of birth

    I agree with the authors above. I used the js function that was for my project. But the js function wasn't activated for a long time until I used an additional plugin for it. I got the manual from my programming teacher, who was implementing this project with me. I want to show him the code in the picture above. I think he'll approve and work on the implementation.

  • Suggested answer
    LeoAlt Profile Picture
    LeoAlt 16,331 on at
    RE: Calculate and populate school grade from date of birth

    Hi partner,

    According to your description, I suggest you to use js function to do this beacuse it's very convenient and it can be flexible according to your needs.

    Here is the sample code for you.

    function getGrade(executionContext) {
        var today=new Date();
        var month = today.getMonth() + 1;//Get current Month
        var day = today.getDate();//Get current Day
        //If today is 04-02, then set the grade/year
        if(month==4&&day==2){
            var formContext = executionContext.getFormContext();
            var birth = formContext.getAttribute("new_Birthday").getValue();
            var birthDayTime = new Date(birth).getTime();
            var nowTime = new Date().getTime();
            var age = Math.ceil((nowTime - birthDayTime/ 31536000000);
            if(age==13){
                formContext.getAttribute("new_gradeyear").setValue("Junior High School Grade 2");
            }
        }
    }

    You said that you only want this function run at 04-02, but in D365 we could not specifies that the code is executed on a particular date, so I add this function in form onload event and if today is 04-02, it will trigger the function.

    Hope it helps.

    Best Regards,

    Leo

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,379 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans