Question

auto calculate age Using RequireJs

Hi Team!

I am attempting to autofill the age based on the date of birth.

Through Bussiness Process I got the age AutoFill, but I need using Require Js (Card Schema)

How to get the current age and where I have to set that filed.

Hoping for Quick Reply.plz find the attachment.

Regards

manikanta

 

 

Like 0

Like

1 comments

Dear Manikanta, 

You can create a method that would calculate the Age and set the Age field in it. After that just call the method in the onEntityInitialized. Here is an example: 

onEntityInitialized: function() {

                this.callParent(arguments);

                this.calculateAge();

            }, 

            

            calculateAge: function(){

                const _MS_PER_DAY = 1000 * 60 * 60 * 24;

                

                var birthDate = this.get("UsrBirthDate"); 

                var currentDate = new Date(); 

                const utc1 = Date.UTC(birthDate.getFullYear(), birthDate.getMonth(), birthDate.getDate());

                const utc2 = Date.UTC(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate());

                this.set("UsrAge",Math.floor((utc2 - utc1) / _MS_PER_DAY / 360));

            }

Best regards, 

Dennis 

Show all comments