Custom calculated fields allow you to create mathematical formulas using C# (C sharp). The formulas you can create and their resulting values are based on the data entered in your records. These fields are read-only since their values come from your formulas. You can create simple formulas using IF statements to return the calculated values, but your statements cannot contain for loops, do while loops, or method declarations.
If you're not familiar with C# (C sharp) or any C programming language, you may want to get assistance from someone who is more familiar with coding.
To create the calculated field:
- Click the profile icon and click System Settings.
- Click Objects and Fields.
- Select the object you want to create the field for (you can create a custom calculated field for Contacts, Organizations, Opportunities, Leads, Projects, and Custom Objects).
- Select Object Fields from the Object Management menu.
- Click New Field.
- Choose Calculated Field.
- Complete the required fields:
- Field Label – Enter the name for your new field. For example, we are going to create a new field under Opportunities called “Revenue minus expenses (you won't be able to use the same field name twice)."
- Field Name - The name will automatically fill after you've added your Field Label, but you can alter it if needed. Note: Field Names are followed by __c (two low dashes, then c).
8. Select the Field Type for the returned value. Your formula must return a value based on the field type you select. If you select a number for your field type, your formula must return a number. The same applies to a checkbox, date, date/time, percent, and text field.
9. Enter your formula in the Field formula. To help build the formula, click the Helpers button.
You can add values to the formula box by double-clicking or dragging any item from the Objects Fields or Functions list, typing directly in the field, or by copying and pasting a provided formula, such as the examples at the end of this article.
Under Object Fields, the different field types are sorted by type. For example, if you want to view the string fields, select String Fields. The Functions list is also sorted by their function types, such as Boolean (True or False), DateTime, and Decimal. When typing your formula, Insightly also has a built-in IntelliSense that provides drop-down options to help complete your code.
To learn more about the functions, click any function and read the description.
10. Click Validate Formula to check your formula can compute. If Insightly cannot validate your formula, an error message will display above the formula field stating why.
11. Click Save Custom Field.
Here are some sample formulas to get you started: