AnsweredAssumed Answered

Create a field manually using another field's value

Question asked by Nour Nour on Jun 16, 2014
Latest reply on Oct 20, 2014 by Alan Beam
To create a field value, I created the vardef extension file and I know where to write this code. I have no problem in finding where to put the code and what files should be included.I tried to make another example where I had to calculate the days since the  contact entered into the system, and it worked very fine. A correct display of days was viewed upon adding my contact.

Now I want to create another field using the birthdate field value present in sugarcrm. This field calculates the age of my contact. Therefore, I wrote this code.

<?php
function getAge()
{

$age=date("Y")-birthdate;

if($view == 'EditView' || $view == 'MassUpdate') { //If this is EditView Or MassUpdate Include a field box
 $age = '<input type=text name=age value={$age} disabled>\n';
 }
 return $age;
}
?>
Sugarcrm does not then show me anything. It does not read birthdate. In the previous example I have mentioned, I used data_entered field and everything worked fine. Sugarcrm read the data_entered field, made calculations and gave me correct number of days.
Now the result I get in this is only 2014 which means sugarcrm read only date("Y") and disregarded birthdate.
I even tried writing $age=birthdate instead just to see if sugarcrm would read birthdate. It did not display anything. 
Sorry for the long essay but this is really important. 
Thanks.
Please if you have any further inquires tell me.



Outcomes