create_derived_value_element

Admin-only MCP tool.

Create a new Derived Value Element in a Formulize form.

Newly created elements appear on the pages of form screens where all other elements in the form already appear. To add a newly created element to a form screen page which only has some existing elements, use the update_form_screen tool.

Element: Derived Value (derived)

Description: An element that derives its value from other elements using custom PHP code. This element allows for calculations or data manipulations based on the values of other form elements. Derived values are automatically recomputed when entries are saved, and in most situations they are also automatically recomputed when connected entries are saved. For example if you have a Workshops form connected to a Bookings form, and the Workshops form has a derived value to keep track of the number of spaces available. The derived value will be updated whenever the Workshop entry is saved, and also whenever connected entries in the Bookings form are created or updated.

When derived values are recomputed, a dataset will be made available to the code in the derived value element. The dataset will contain all the data in the entry being saved, plus all the data from connected entries in other forms. To access this data, use PHP variables named after the element handles, ie: $workshop_name, $booking_date, etc. These variables will resolve to the value(s) of that element in the current dataset. There may be multiple values for a given element in the dataset. In that case, the variable will resolve to an array of values; otherwise it will be a scalar. Use is_array() to detect whether an element has multiple values at present or not.

For more details on the internal Formulize API functions and methods you can use in this code, use the get_documentation tool.

Examples:

  • A derived value element that puts the first name and last name together: { code: “$value = $profile_first_name.’ ‘.$profile_last_name;” }
  • A derived value element that calculates a 10% tax on a subtotal field: { code: “$value = $order_subtotal * 0.10;”, decimals: “2”, prefix: “$” }
  • A derived value element that calculates the spaces remaining in a workshop based on the number of bookings: { code: “ $numberOfBookings = 0; if(!empty($bookings_name)) {
    $numberOfBookings = is_array($bookings_name) ? count($bookings_name) : 1;
    }
    $value = $workshop_max_spaces - $numberOfBookings; “
    }

Properties

Property Type Required? Description
form_id integer Required

Required. ID of the form that this will be part of.

caption string Required

Required. The label for the Derived Value Element as it will appear to users in forms and in lists.

properties object Required

Required. Additional configuration settings for the Derived Value Element.

code string Required

PHP code that derives a value from other elements. In the PHP code, the value must be assigned to a variable called $value. Refer to other elements in this and other forms, using variables named after their element handles, ie: $profile_first_name

decimals integer Optional

If the value will be a number, this is the number of decimal places to allow. Default is 0

prefix string Optional

If the value will be a number, this is text to show before the number. Default is

decimalsSeparator string Optional

If the value will be a number, this is the character to use as the decimal separator. Default is .

thousandsSeparator string Optional

If the value will be a number, this is the character to use as the thousands separator. Default is ,

suffix string Optional

If the value will be a number, this is text to show after the number. Default is

column_heading string Optional

Optional. The heading to use at the top of a column in lists of entries. If not specified, the caption will be used. Some captions are long and descriptive, and a shorter heading would be more appropriate for in a list of data.

help_text_for_users string Optional

Optional. A longer description or help text for the Derived Value Element, shown to users filling out the form. This is NOT an internal notes field, this content appears as part of the element.

principal_identifier boolean Optional

Optional. Whether the Derived Value Element is the principal identifying element for entries in this form. Principal identifiers are used in various places in Formulize to represent an entry. The Principal Identifier would typically be a ‘Name’ text box or other element that unique identifies the entry. Each form can only have one Principal Identifier. If a form has a Principal Identifier, and another element is created or updated with this value set to true, the existing Principal Identifier will be replaced with the new one. Default: false.

disabled boolean Optional

Optional. Whether the Derived Value Element element is disabled (visible but not usable) in the form. Default: false.

handle string Optional

This is the internal name, used in the database and in API calls. This is optional and does not normally need to be specified, as the system will determine it automatically from the form title and element caption. If the user specifically requests a handle, use this to force the handle to be a certain value. The system may still modify it for uniqueness, so check the tool result to see the actual handle used in by system. Maximum length is 64 characters.

display_conditions array of object Optional

Optional. A given form entry must meet these conditions in order for this element to be displayed; otherwise it is not shown. Each condition includes an element, an operator, a value, and a ‘type’ flag indicating the logical set the condition belongs to: ‘match-all’ or ‘match-one-or-more’. Multiple match-all conditions are joined with a logical AND operator, and multiple match-one-or-more conditions are joined with a logical OR operator. Provide a list of conditions to restrict when the element is displayed; if you omit this property (or provide an empty array) it has no conditions and is always displayed. When setting conditions based on linked elements, do not use foreign keys as values, and instead use the readable value which this tool understands automatically. Use the special value “{BLANK}” (without quotes) to match blank values.
Examples:

  • [ { “element”: “status”, “operator”: “=”, “value”: “Approved”, “type”: “match-all” } ]
  • [ { “element”: “award_value”, “operator”: “>”, “value”: “500”, “type”: “match-all” }, { “element”: “award_year”, “operator”: “=”, “value”: “2026”, “type”: “match-all” } ] Match size 40 pants OR green pants:
  • [ { “element”: “pant_size”, “operator”: “=”, “value”: “40”, “type”: “match-one-or-more” }, { “element”: “pant_color”, “operator”: “=”, “value”: “green”, “type”: “match-one-or-more” } ] Match incomplete orders that are due before today, and are going to either Canada or Mexico:
  • [ { “element”: “order_state”, “operator”: “=”, “value”: “incomplete”, “type”: “match-all” }, { “element”: “order_due_date”, “operator”: “<”, “value”: “{TODAY}”, “type”: “match-all” }, { “element”: “order_destination”, “operator”: “=”, “value”: “Canada”, “type”: “match-one-or-more” }, { “element”: “order_destination”, “operator”: “=”, “value”: “Mexico”, “type”: “match-one-or-more” } ] Do not use foreign key values with linked elements; use the readable value instead:
  • Incorrect: [ { “element”: “assigned_judge”, “operator”: “LIKE”, “value”: “509”, “type”: “match-all” } ]
  • Correct: [ { “element”: “assigned_judge”, “operator”: “LIKE”, “value”: “Wapner”, “type”: “match-all” } ]
placement string Optional

The canonical position of the element in the form. This order is used on every form screen page that this element has been added to (newly created elements are automatically added to all pages that currently have all existing elements; to add an element to a page that has only some existing elements, use the update_form_screen tool). Use “top” to make this element the first element in the form, use “bottom” to make this element the last (which is the default for new elements), or use an element handle to place this element immediately after that element (based on the live state of the form at the time of this specific request; re-fetch get_form_details first if you need to see the current element order). On updates, omit this to leave the current position unchanged.

data_type string Optional

Optional. The MariaDB data type to be used for the field in the database where this data will be stored. The system will default to text in most cases, but will set smart defaults if the type is specifically a number box or a linked element storing foreign keys, etc. Generally this does not need to be specified, but can be used if the user has specifically stated that a certain data type must be used for a given element. Valid types are: text, int(x), decimal(x,y), date, datetime, time, char(x), varchar(x). For int(x), the x is the number of digits to display in MariaDB when showing the number. For decimal(x,y), the x is the total number of digits, and y is the number of digits after the decimal point. For char(x) and varchar(x), the x is the maximum number of characters to store.

← Back to the MCP reference