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:
-
copy detailviewdefs.php file from ‘{ROOT}/public/legacy/modules/Leads/metadata/detailviewdefs.php’ at ‘{ROOT}/public/legacy/custom/modules/Leads/metadata/detailviewdefs.php’
-
Add global $current_user at the top in the detailviewdefs.php file
global $current_user;
$viewdefs ['Leads'] =....
- 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',
),
),
- 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]],
],
],
],
],
],
-
Run the following command
php bin/console cache:clear to clear the cache/prod. -
Test if convert lead button is hidden when assigned user id not equal to current user id
i tried it and it is working thank you
i have a problem with this solution code of detailviewdefs keeps changing and removing global $current_user does this happen to anybody