[Vtigercrm-developers] Calculated Field Made Easy (Same Module)

Christophe Humbert chrissc.humbert at gmail.com
Sun Apr 19 13:11:53 GMT 2015


Please find a little trick to make a calculated field in the same module
1. Create your field normally with the target format (text, integer etc...)
2. Edit the file
/layouts/vlayout/modules/the_module_youhavecreatedyourfieldin/resources/Edit.js
3. Add in the file the code
This is an example code to calculate Age of a contact based on his birthday:
What I do, I hook the event change on the field triggering the calculation
i.e Birthday
As for the name of your custom field created in 1. open the page source of
the detail view of your module and you will find the field cf_XXX which
will be your target field or result of your calculation
I push the result of my calculation in my custom field
/**
* Function to calculate Age based on birthday field change
*/
jQuery('[name="birthday"]',form).change(function() {
var dateBirth =
Vtiger_Helper_Js.getDateInstance(jQuery('[name="birthday"]',form).val(),jQuery('[name="birthday"]',form).attr("data-date-format"));
jQuery('[name="cf_755"]',form).val( Math.floor((Date.now()-dateBirth) /
(31557600000)));
});

Happy Hacking

Christophe Humbert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20150419/93ba141e/attachment.html>


More information about the vtigercrm-developers mailing list