Adding Custom Field Logic

1. Example of Field Logic

In this example we are going to see how to add field logic in order to:

  • Hide a field depending on another fields value.

  • Mark a field as required depending on another field value

Hide a field

As an example of how to hide a field. We are going to add configuration to the priority field in order to hide it whenever the Case’s State is set to Closed. When the Case is closed the "Priority" field is no longer necessary and thus we don’t need it to display. As a result we will see something like the screenshot below shows.

Closed.png

Make a field required

On the other hand, it would be great if when the Case’s Status is set to Open_Assigned, the Priority field could be marked as a required field, as shown on the following screenshot.

For this we will add a second entry to the logic configuration. as you can see on the code snippet below.

Open_Assigned.png

2. How does this look as Code?

The following code block shows an example of the configuration we need to add to the vardefs in order to get the logic described on the previous section

<?php

...

        'priority' => array(
            'name' => 'priority',
            'vname' => 'LBL_PRIORITY',
            'type' => 'enum',
            'options' => 'case_priority_dom',
            'len' => 100,
            'audited' => true,
            'comment' => 'The priority of the case',
            'logic' => [
                'display' => [
                    'key' => 'displayType',
                    'modes' => ['detail', 'edit', 'create'],
                    'params' => [
                        'fieldDependencies' => [
                            'state',
                        ],
                        'targetDisplayType' => 'none',
                        'activeOnFields' =>  [
                            'state' => [ 'Closed']
                        ]
                    ]
                ],
                'required' => [
                    'key' => 'required',
                    'modes' => ['edit', 'create'],
                    'params' => [
                        'fieldDependencies' => [
                            'status',
                        ],
                        'activeOnFields' =>  [
                            'status' => [ 'Open_Assigned']
                        ]
                    ]
                ]
            ]
        ),


        ...

3. The configurations explained

There are two different types of logic used in the example above, DisplayType and Required. Which we are going to cover next.

DisplayType

<?php

...

                'display' => [
                    'key' => 'displayType',
                    'modes' => ['detail', 'edit', 'create'],
                    'params' => [
                        'fieldDependencies' => [
                            'state',
                        ],
                        'targetDisplayType' => 'none',
                        'activeOnFields' =>  [
                            'state' => [ 'Closed']
                        ]
                    ]
                ],

        ...

Properties description

  • Key

    • The key within the named display array is stating which logic type will be used for the following. In this case it’s displayType.

  • Modes

    • Modes is what views you would like your logic to take affect on, as shown above it will be detail, edit and create. Another example of a mode that could be selected could be list for example.

  • Params

    • Each type of field logic will accept different params.

    • DisplayType logic accepts the following:

      • fieldDependencies is where you declare the field(s) that you would like your logic to depend on

      • activeOnFields is where you declare the field/values that trigger the change of the field to a required field

Required

<?php

...

                'required' => [
                    'key' => 'required',
                    'modes' => ['edit', 'create'],
                    'params' => [
                        'fieldDependencies' => [
                            'status',
                        ],
                        'activeOnFields' =>  [
                            'status' => [ 'Open_Assigned']
                        ]
                    ]

        ...

Properties description

  • Key

    • The key within the named required array is stating which logic type will be used for the following. In this case it’s required.

  • Modes

    • Modes is what views you would like your logic to take affect on, as shown above it will be detail, edit and create. Another example of a mode that could be selected could be list for example.

  • Params

    • Each type of field logic will accept different params.

    • required logic accepts the following:

      • fieldDependencies is where you declare the field(s) that you would like your logic to depend on

      • activeOnFields is where you declare the field/values that trigger the change of the field to a required field

Customising this functionality

If you would like to add this functionality into your CRM code or add this and change it to fit your requiremnts then please add it to <suite8path>/public/legacy/custom/Extension/modules/<module>/Ext/Vardefs/<any-filename>.php.

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