Logic Operators

When making these changes be sure to make them in the custom directory, ie: 'public/legacy/custom/modules/<module>/…​'

When adding this configuration, it can be added to the vardefs.php or the detailviewdefs.php.

SuiteCRM 8 has 6 operators that can be used in configuration.

Available Operators

Greater than

    'name' => 'annual_revenue',
    'comment' => 'Annual revenue for this company',
    'label' => 'LBL_ANNUAL_REVENUE',
    'logic' => [
        'update-when-more-than-10-employees' => [
            'key' => 'updateValue',
            'modes' => ['detail', 'edit', 'create'],
            'params' => [
                'fieldDependencies' => [
                    'employees',
                ],
                'targetValue' => '1000',
                'activeOnFields' => [
                    'employees' =>     [
                        'operator' => 'greater-than',
                        'value' => 10
                    ],
                ]
            ]
        ],
    ]

In the example above, the Annual Revenue updated to 1000 if Employees is greater than 10.

Is Empty

    'name' => 'description',
    'comment' => 'Full text of the note',
    'label' => 'LBL_DESCRIPTION',
    'displayLogic' => [
        'hide_on_website' => [
            'key' => 'displayLogic',
            'modes' => ['detail', 'edit', 'create'],
            'params' => [
                'fieldDependencies' => [
                    'website',
                ],
                'targetDisplayType' => 'none',
                'activeOnFields' => [
                    'website' => [['operator' => 'is-empty']]
                ]
            ]
        ],
    ]

In the example above we are hiding the description field if the website field is empty.

Is Equal

    'name' => 'annual_revenue',
    'comment' => 'Annual revenue for this company',
    'label' => 'LBL_ANNUAL_REVENUE',
    'logic' => [
        'update-when-10-employees' => [
            'key' => 'updateValue',
            'modes' => ['detail', 'edit', 'create'],
            'params' => [
                'fieldDependencies' => [
                    'employees',
                ],
                'targetValue' => '1000',
                'activeOnFields' => [
                    'employees' =>     [
                        'operator' => 'is-equal',
                        'value' => 10
                    ],
                ]
            ]
        ],
    ]

In the example above when employees is 10, update Annual Revenue to 1000.

Less Than

    'name' => 'annual_revenue',
    'comment' => 'Annual revenue for this company',
    'label' => 'LBL_ANNUAL_REVENUE',
    'logic' => [
        'display' => [
            'key' => 'updateValue',
            'modes' => ['detail', 'edit', 'create'],
            'params' => [
                'fieldDependencies' => [
                    'employees',
                ],
                'targetValue' => '500',
                'activeOnFields' => [
                    'employees' =>     [
                        'operator' => 'less-than',
                        'value' => 5
                    ],
                ]
            ]
        ],
    ]

In the example above, the Annual Revenue updated to 1000 if Employees is less than 10.

Not Empty

    'name' => 'annual_revenue',
    'comment' => 'Annual revenue for this company',
    'label' => 'LBL_ANNUAL_REVENUE',
    'logic' => [
        'update-when-employee-set' => [
            'key' => 'updateValue',
            'modes' => ['detail', 'edit', 'create'],
            'params' => [
                'fieldDependencies' => [
                    'employees',
                ],
                'targetValue' => '1',
                'activeOnFields' => [
                    'employees' =>     [
                        'operator' => 'not-empty',
                    ],
                ]
            ]
        ],
    ]

In the example above if the Employee field has any value, then Annual Revenue will update to have the value 1.

Not Equal

    'name' => 'annual_revenue',
    'comment' => 'Annual revenue for this company',
    'label' => 'LBL_ANNUAL_REVENUE',
    'logic' => [
        'update-not-10-employees' => [
            'key' => 'updateValue',
            'modes' => ['detail', 'edit', 'create'],
            'params' => [
                'fieldDependencies' => [
                    'employees',
                ],
                'targetValue' => '50000',
                'activeOnFields' => [
                    'employees' =>     [
                        'operator' => 'not-equal',
                        'values' => ['10']
                    ],
                ]
            ]
        ],
    ]

In the example above, if the employees field is not equal to 10 then the value will be updated to 50000.

You can add the check to more than one value by adding more values:

    'employees' => [
        'operator' => 'not-equal',
        'values' => ['10', '15', '25']
    ],

Multiple operators on the same field

You can also use multiple operators on the same field:

    'name' => 'industry',
    'comment' => 'The company belongs in this industry',
    'label' => 'LBL_INDUSTRY',
    'displayLogic' => [
        'hide_on_name' => [
            'key' => 'displayType',
            'modes' => [
                0 => 'detail',
                1 => 'edit',
                2 => 'create',
            ],
            'targetDisplayType' => 'none',
            'params' => [
                'fieldDependencies' => [
                    'employees'
                ],
                'activeOnFields' => [
                    'employees' => [
                        //AND
                        [
                            'operator' => 'greater-than',
                            'value' => 5
                        ],
                        [
                            'operator' => 'less-than',
                            'value' => 25
                        ],
                        [
                            'operator' => 'not-equal',
                            //OR
                            'values' => [15, 20]
                        ],
                        ['operator' => 'not-empty'],
                    ],
                ],
            ],
        ],
    ],

Comparing to a field instead of a value

For operators where you compare with a single value using 'value' ⇒ <some-value>, it is possible to instead compare with another field’s value, by using 'field' ⇒ '<field-name>'

Field comparison is available on the following operators:

  • less-than

  • greater-than

  • is-equal

  • not-equal

The following snippet provides an example of how to use the field instead of the value

    'name' => 'prefered_contact',
    'displayLogic' => [
        'hide_on_single_phone' => [
            'key' => 'displayLogic',
            'modes' => ['detail', 'edit', 'create'],
            'params' => [
                'fieldDependencies' => [
                    'phone_office',
                ],
                'targetDisplayType' => 'none',
                'activeOnFields' => [
                    'phone_office' => [
                        'operator' => 'is-equal',
                        'field' => 'phone_fax'
                    ],
                ]
            ]
        ],
    ]

Content is available under GNU Free Documentation License 1.3 or later unless otherwise noted.