Re: Role-based dropdown not working

Here is the code I used for my specific requirements. Thanks André Lopes for your Role function and Cédric Mourizard for your input. No doubt the code could be more elegantly constructed and optimised but I hope this provides some guidance.

So file setoptions_accounts_dep.php saved into...

<site>\custom\Extension\modules\Accounts\Ext\Dependencies

followed by QRR which merges into file deps.ext.php in...

<site>\custom\modules\Accounts\Ext\Dependencies

Notes on code below:

Key values in DD lists are dictated by integration requirements with another application

Scenario 1 : new or existing 'non-client' category - limit choice to 'non-client' settings for all users

Scenario 2 : 'Client' settings - choices presented to Data Admin users

Scenario 3 : 'Active Client' for non Data Admin users - this simply allows display of existing setting

Scenario 4 : 'Inactive Client' for non Data Admin users - this simply allows display of existing setting

Scenario 5 : 'Hold Client' for non Data Admin users - this simply allows display of existing setting

End result is...

  • users can freely manage records within the 'non-client' categories
  • Data Admin people can manage records within the 'client' categories (we could extend that out to allow them to change back into the 'non-client' categories if required)
  • For 'client' categories, general users cannot change that setting but can at least see it (which is the original bug in Sugar role based dropdowns)

<?php
/*
Control changes to Category (account_type)
Keys:
1 - Inactive Client
2 - Hold Client
3 - Active Prospect
4 - Inactive Prospect
5 - Active Client
21 - Lead
22 - Referral Source
23 - Contact
24 - Inactive Contact
25 - Inactive Lead
*/


// One -- empty(new), Lead, Contact, Referral Source, Active Prospect, Inactive Prospect, Inactive Contact, Inactive Lead
$dependencies['Accounts']['setoption_dep_one'] = array(
'hooks' => array("edit","save"),
// 'trigger' => 'true',
'trigger' => 'isInList($account_type, createList("", "21", "23", "22", "3", "4", "24", "25"))',
'triggerFields' => array('account_type'),
'onload' => true,
'actions' => array(
array(
'name' => 'SetOptions',
'params' => array(
'target' => 'account_type',
'keys' => 'createList("","21", "23", "22", "3", "4", "24", "25")',
'labels' => 'createList("","Lead", "Contact", "Referral Source", "Active Prospect", "Inactive Prospect", "Inactive Contact", "Inactive Lead")'
),
),
),
);

// Two -- Active Client, Inactive Client, Hold Client - but only for Admin People
$dependencies['Accounts']['setoption_dep_two'] = array(
'hooks' => array("edit","save"),
// 'trigger' => 'true',
'trigger' => 'and(isInList($account_type, createList("5", "1", "2")), isUserInRoleList(createList("11. Admin Support")))',
'triggerFields' => array('account_type'),
'onload' => true,
'actions' => array(
array(
'name' => 'SetOptions',
'params' => array(
'target' => 'account_type',
'keys' => 'createList("5", "1", "2")',
'labels' => 'createList("Active Client", "Inactive Client", "Hold Client")'
),
),
),
);

// Three -- Active Client - for all but Admin People - so visible
$dependencies['Accounts']['setoption_dep_three'] = array(
'hooks' => array("edit","save"),
// 'trigger' => 'true',
'trigger' => 'and(isInList($account_type, createList("5")), not(isUserInRoleList(createList("11. Admin Support"))))',
'triggerFields' => array('account_type'),
'onload' => true,
'actions' => array(
array(
'name' => 'SetOptions',
'params' => array(
'target' => 'account_type',
'keys' => 'createList("5")',
'labels' => 'createList("Active Client")'
),
),
),
);

// Four -- Inactive Client - for all but Admin People - so visible
$dependencies['Accounts']['setoption_dep_four'] = array(
'hooks' => array("edit","save"),
// 'trigger' => 'true',
'trigger' => 'and(isInList($account_type, createList("1")), not(isUserInRoleList(createList("11. Admin Support"))))',
'triggerFields' => array('account_type'),
'onload' => true,
'actions' => array(
array(
'name' => 'SetOptions',
'params' => array(
'target' => 'account_type',
'keys' => 'createList("1")',
'labels' => 'createList("Inactive Client")'
),
),
),
);

// Five -- Hold Client - for all but Admin People - so visible
$dependencies['Accounts']['setoption_dep_five'] = array(
'hooks' => array("edit","save"),
// 'trigger' => 'true',
'trigger' => 'and(isInList($account_type, createList("2")), not(isUserInRoleList(createList("11. Admin Support"))))',
'triggerFields' => array('account_type'),
'onload' => true,
'actions' => array(
array(
'name' => 'SetOptions',
'params' => array(
'target' => 'account_type',
'keys' => 'createList("2")',
'labels' => 'createList("Hold Client")'
),
),
),
);