Question

Age Calculation on Edit Page

Hi Team I want to calculate the Age in real-time.  For that, I have created a system date field in the system and by default add the current date value to it. 

Please check the code mentioned in the screenshot.

And the output in Age field (Integer field) after taking the difference of current date - dob is coming unexpected pls check the code. 

 

Like 0

Like

4 comments

Below has the similar functionality which you can try,

https://community.creatio.com/questions/calculation-fields-difference-b…

Hy this code doesn't work for me I am not able to open my section page.

Bhumika Bisht,

You may need to share the error that you are getting in console to check further . 

Bhumika Bisht,

 In your scripts, you try to update the age field in the onEntityInitialized event. However, in your code you only try to set the age when the page is in the isAddMode.  In this case, when you click on the "New" button, the page is ready trying to calculate the field.

 

At that moment the value from UsrDateOfBirth is empty, but in your code you do not check it and directly use the value as a Date. Therefore you will get the error on the javascript code which will stop rendering your page.

 

Please check the value of dob before you using it to get the age.

if( dob==null )

Hopefully this will help you.

 

regards,

 

Cheng Gong

Show all comments