Hide/show convert button

how can i hide convert lead button if current user is not lead owner

i used this solution but i don’t know what to place here

"params" => [
                                "activeOnFields" => [
                                    "phone_fax" => ["01234 999999"],
                                ],

how to get current user id

Using ‘global $current_user;’ at the top of detailviewdefs.php file and we can get current user id by $current_user->id.

The following solution worked for me. The solution might not be efficient but works for me.

Steps:

  1. copy detailviewdefs.php file from ‘{ROOT}/public/legacy/modules/Leads/metadata/detailviewdefs.php’ at ‘{ROOT}/public/legacy/custom/modules/Leads/metadata/detailviewdefs.php’

  2. Add global $current_user at the top in the detailviewdefs.php file

global $current_user;
$viewdefs ['Leads'] =....
  1. Create a hidden field in detailviewdefs.php file for assigned_user_id next to ‘assigned_user_name’ field as shown below
7 =>
	array(
		0 =>
			array(
				'name' => 'assigned_user_name',
				'label' => 'LBL_ASSIGNED_TO',
			),
		1 => array(
			'name' => 'assigned_user_id',
			'customCode' => '{$fields.assigned_user_id.value}',
			'display' => 'none',
			),
	),
  1. Update recordAction of the ‘convert-lead’ definition for displayLogic as shown below:
'actions' => [
	'convert-lead' => [
		'key' => 'convert-lead',
		'labelKey' => 'LBL_CONVERTLEAD',
		'asyncProcess' => true,
		'params' => [],
		'modes' => ['detail'],
		'acl' => ['edit'],
		'display'=>'hide',
		'displayLogic' => [
			'convert-lead-visibility' => [
				'key' => 'displayType',
				'modes' => ['detail'],
				'targetDisplayType' => 'default',
				'params' => [
					'fieldDependencies' => ['assigned_user_id'],
					'activeOnFields' => [
						'assigned_user_id' => [['operator' => 'is-equal','value'=>$current_user->id]],
					],
				],
			],
		],
	],
  1. Run the following command
    php bin/console cache:clear to clear the cache/prod.

  2. Test if convert lead button is hidden when assigned user id not equal to current user id

1 Like

i tried it and it is working thank you

1 Like