Adding formulas/field calculations when creating custom fields via the manifest file.

Hey guys, 

I hope you are all well. I am currently work on a package to update our customer onboarding process. It would be preferred to install a single package in production and the configuration is complete except for adding the fields to the record layout.

In this process, I have check boxes on the Cases module an agent would check to create a related support setup ticket. Once this field is checked, there are other dependencies which become required, a text box should appear and be required. Normally I would just add the dependent formula in studio when creating the field, but when creating the fields with my manifest file, it is not clear how to add a dependent formula to a field.

Can anyone point me in the right direction? 

  • Hi,

    I believe you can make this field required through Vardefs file and make the field visible through Set Visibility in SugarCRM. Please go through Set Visibility to know more about how to make field visible based on other filed conditions.

    You can make a field required by adding this code in vardefs folder.

    1. Create file on this location "custom/Extension/modules/<module_name>/Ext/Vardefs/<example_c>.php".
    <module_name> should be replaced by your module name.
    2. Add code in <example_c>.php file.

    $dictionary['<module singular>']['fields']['example_c']['required'] = true;

    To be very clear <module singular> refers to singular label of your module name if it is for Accounts module you have to set it as Account and example_c refers to your field name to which you want to make as required.
    3.After adding this code please go to Administration->Repair and perform Quick Repair and Rebuild. By doing this both changes you should be able to achieve the things.

    4. You can make this changes, and  do manifest file to deploy into your Instance

  • Set Visibility was exactly what I was looking for. Thank you Poojitha. 

  • Hi ,

    If you are trying to add a formula for a calculated field from your manifest.php file, you only have to indicate the path corresponding to the vardef of your module:
    <sugar_path> \ custom \ Extension \ modules \ <your_custom_module> \ Ext \ Vardefs
    And in your file: sugarfield_name_of_your_field_file_c.php
    you must write this instruction:
    $ dictionary ['<your_custom_module>'] ['fields'] ['<your_field_name>_c'] ['formula'] = '<here is your sugar logic formula>';
    And you can also add a dependency of another field:
    $ dictionary ['<your_custom_module_name>'] ['fields'] ['<your_field_name>'] ['dependency'] = 'equal ($<field to validate>, "<value of field to validate>")';

    For example: equal ($status, "Active").

    I hope it helps.
    Regards.