Formula Custom Fields

Created by School Edtech, Modified on Wed, 2 Apr at 6:01 AM by School Edtech

Using Custom Field Formulas in SchooledTech

1. Identify the Custom Field Numbers

Before you can create a formula, you need to find the field numbers for the custom fields you want to use.

Steps:

  1. Go to the front end of your SchooledTech page.

  2. Right-click on the page and select Inspect (or press F12 on your keyboard).

  3. In the Elements tab, look for the custom field values. They will look something like this:

    FieldVals[229].Val
    

    The number 229 is the custom field ID for that field.

  4. Note the field number (e.g., 229 for the "owed" field).


2. Creating Simple Custom Field Formulas

Once you know the custom field numbers, you can create formulas for various operations. Below are examples of how to subtract, divide, multiply, and add fields.

Example 1: Subtracting Two Fields (Owed - Paid)

If you have two custom fields:

  • Owed (e.g., field 229)

  • Paid (e.g., field 230)

To calculate the balance by subtracting the "Paid" amount from the "Owed" amount, you can use the following formula:

javascriptCopyEdit
( (+getField(229).value) - (+getField(230).value) ).toFixed(2)

This will subtract the value in Paid (field 230) from the value in Owed (field 229) and format the result to two decimal places.

Example 2: Adding Two Fields

If you want to add the values of Field 229 and Field 230, you can use this formula:

javascriptCopyEdit
( (+getField(229).value) + (+getField(230).value) ).toFixed(2)

Example 3: Multiplying Two Fields

To multiply Field 229 and Field 230:

javascriptCopyEdit
( (+getField(229).value) * (+getField(230).value) ).toFixed(2)

Example 4: Dividing Two Fields

If you want to divide Field 229 by Field 230:

javascriptCopyEdit
( (+getField(229).value) / (+getField(230).value) ).toFixed(2)

3. Using Multiple Fields in a Formula

You can work with more than two fields. Here’s an example of a formula that uses three custom fields:

Example 5: Adding Three Fields

If you want to add Field 229, Field 230, and Field 231:

javascriptCopyEdit
( (+getField(229).value) + (+getField(230).value) + (+getField(231).value) ).toFixed(2)

Example 6: Subtracting Three Fields

To subtract Field 230 and Field 231 from Field 229:

javascriptCopyEdit
( (+getField(229).value) - (+getField(230).value) - (+getField(231).value) ).toFixed(2)

Example 7: Multiplying Three Fields

To multiply Field 229, Field 230, and Field 231:

javascriptCopyEdit
( (+getField(229).value) * (+getField(230).value) * (+getField(231).value) ).toFixed(2)

Example 8: Dividing Three Fields

If you want to divide Field 229 by the result of Field 230 divided by Field 231:

javascriptCopyEdit
( (+getField(229).value) / (+getField(230).value) / (+getField(231).value) ).toFixed(2)

4. Handling Empty or Invalid Values

To avoid errors if some fields are empty or have invalid data, you can add a fallback value like 0 using || 0. For example:

javascriptCopyEdit
( (+getField(229).value || 0) - (+getField(230).value || 0) ).toFixed(2)

This ensures that if a field is empty or invalid, it will be treated as 0.


5. Using ChatGPT to help you with formulas

You can ask for JavaScript formulas or JavaScript custom field calculations

This is especially helpful when adding many fields, you can ask chatgpt something like:
Give me the javascript formula to add up the fields 100 thru 110.

This is also helpful for Multi Notes, which contain the date and the field you want to add (although you can also enter text in the field, you can use it for numbers as well).  The date needs to "parsed" or separated first in order to ignore it.

The answer will look like this:

(  JSON.parse(getField(968).value).reduce((sum, note) => sum + (+note.val || 0), 0) ).toFixed(2)

 

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article