displayLogic show/hide

Hi @all

I’am playing around with the displayLogic function to show/hide fields on certain conditions. Currently I’d like to show a dropdown field for a lost reason when the sales stage is set to “closed lost”.

So I added the custom field and edited the file custom/Extension/modules/Opportunities/Ext/Vardefs/_override_sugarfield_opty_lost_reason_c.php as follow:

$dictionary['Opportunity']['fields']['opty_lost_reason_c']['inline_edit']='1';
$dictionary['Opportunity']['fields']['opty_lost_reason_c']['labelValue']='Lost reason';
$dictionary['Opportunity']['fields']['opty_lost_reason_c'] = array(
    'displayLogic' => [
        'show_on_lost' => [
            'key' => 'displayType',
            'modes' => ['detail','edit','create'],
            'params' => [
                'fieldDependencies' => [
                    'sales_stage',
                ],
                'targetDisplayType' => 'show',
                'activeOnFields' => [
                    'sales_stage' => ['Closed Lost'],
                ]
            ]
        ],
    ]
);

I set the 'targetDisplayType' => 'show' according to the docs Adding Field Display Logic" in section “Target Display Type”. After a Quick Repair and clearing the browsers cache, the desired behaviour wasn’t there. Actually nothing happend. I tried it a few weeks ago with the same result. So I had to Invert the logic and HIDE the field on certain conditions - which impo is a complete nonsense - meaning list all the options, where the field is hidden:

$dictionary['Opportunity']['fields']['opty_lost_reason_c']['inline_edit']='1';
$dictionary['Opportunity']['fields']['opty_lost_reason_c']['labelValue']='Lost reason';
$dictionary['Opportunity']['fields']['opty_lost_reason_c'] = array(
    'displayLogic' => [
        'show_on_lost0' => [
            'key' => 'displayType',
            'modes' => ['detail','edit','create'],
            'params' => [
                'fieldDependencies' => [
                    'sales_stage',
                ],
                'targetDisplayType' => 'none',
                'activeOnFields' => [
                    'sales_stage' => ['Prospecting'],
                ]
            ]
        ],
        'show_on_lost1' => [
            'key' => 'displayType',
            'modes' => ['detail','edit','create'],
            'params' => [
                'fieldDependencies' => [
                    'sales_stage',
                ],
                'targetDisplayType' => 'none',
                'activeOnFields' => [
                    'sales_stage' => ['Qualification'],
                ]
            ]
        ],
        ...and so on with all the rest of the options...

    ]
);

This is working fine but complicated, since I have to update the code everytime I would add another option to the list. Is there a better way or is this by design? Thank you for your help.

Btw: I am using SuiteCRM 8.7.1 with PHP 8.1

Cheers,
Carsten

Can you try setting a list for the activeOnFields as shown here.

activeOnFields [
    'sales_stage' => [
         ['Qualification', 'Prospecting'],
     ],
 ],

Please note the list of list (two square brackets)

Nope, isn’t working.

Anyway, it would be mor efficient, if you can turn the logic around and tell the system WHEN to SHOW instead of WHEN to HIDE. :slight_smile:

We can achieve this by setting the default display to none. Then displayType logic will set target display to show. Here is a working example from my local application.
The next step field is displayed when sales stage is qualification or prospecting and so on.

 0 => array(
		  'name' => 'next_step',
		  'display' => 'none',
		  'displayLogic' => [
			'show_next_step' => [
				'key' => 'displayType',
				'modes' => ['create','edit','detail'],
				'params' => [
					'fieldDependencies' => ['sales_stage'],
					'activeOnFields' => [
							'sales_stage' => [
									['operator' => 'is-equal','values' => ['Prospecting','Value Proposition','Qualification']],
								],							
					],
				],
			],
		  ],
		  ),
1 Like

hmm… sounds very interesting, but unfortunately, it isn’t working. Where did you put this logic into? “custom/Extension/modules/Opportunities/Ext/Vardefs/[file].php”?

public/legacy/custom/modules/Opportunities/metadata/detailviewdefs.php

Works like a charm! :smiling_face_with_three_hearts: love it! Thank you @Harshad for your help.

1 Like