Lead Dropdown selected depending user role / group

Hi everyone,

For the lead-source field on Leads module. Depending on Role & Group of connected user, i need to select a particular value and make the dropdown not editable by this user.

For example
Dropdown values
1 - Social
2 - Internal
3 - External …

If the connected user has “External” Role and is in “Call-center” group i need the dropdown value “External” to be selected and user can’t modify.

So far i tried by adding a after_ui_frame hook, witch verify the Role and Group of connected user and if corresponding to my rules then --> echo “<script> my js code</script>”. I barely succeed to make it functionnal but this results in this make a bug that forbid to add dashlets on dashboards … (but no errors in log and no error in dev console)

See an extract of code :

//in logic_hooks.php
$hook_array['after_ui_frame'][] = array(
  10, //Hook version
  'Disable lead source choice.',  //Label
  'custom/include/custom_ui.php', //Include file
  'customUi', //Class
  'hideLeadSource' //Method

// in custom/include/custom_ui.php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

class customUi {

	function hideLeadSource($event,$arguments){

		if(  (!isset($_REQUEST['sugar_body_only']) || $_REQUEST['sugar_body_only']!=true) && $_REQUEST['action']!='modulelistmenu' && $_REQUEST['action']!='Popup' && empty($_REQUEST['to_pdf']) && ( !empty($_REQUEST['module']) && $_REQUEST['module']!='ModuleBuilder') && empty($_REQUEST['to_csv'])) {

			global $sugar_config, $current_user;

			$isExterneRole = in_array("Externes", ACLRole::getUserRoleNames($current_user->id));
			if($isExterneRole) {    				
				$securityGroup = new SecurityGroup();
				$currentUserGroup = $securityGroup->getUserSecurityGroups($current_user->id);
				if (isset($securityGroupsData[$currentUserGroup])) {
					echo my js code to select value and hide or disable dropdown

Maybe there is a better way to do this.

Thank you :slight_smile:

Hello Nico,
Todo that, I suggest create a custom field type of function in Leads module instead use after ui frame hook, because after ui frame will impact on all modules.
How to use field type of function. You can reference line_items field in Quotes module or Invoices module. Basically, field type of function will support you render anything you want. For example: String, html,… with html you can render dropdown base on the condition you want.


Hi @nhat.thieu and thank for your answer but i have really no idea on how to “create a custom field type of function in Leads module” :smiley:

i know that ui frame hook will impact all modules (and make the add dashlets not work) , so presently i am trying to override the Lead view.edit.php but i don’t how to render my specific html :-/

As I have suggested bellow. You please go to modules/AOS_Quotes/vardefs.php. Search ‘line_items’. you can see field def type of function. And you can base on it and create a custom field for Leads module. :smile:

oh ok i’ll have a look to this. I’m begineer on suiteCrm, i don’t know yet what are all those AO* Modules … is there a documentation on all these ?


One of several variants:

You can use different forms for different user/role. look at this posts. It wil be work for editview too.

change the file name of form:

assign the name of form in cache

One of form can be by default but other can have hidden panels or fields as readonly.

thank you for your answer. like i said before, i tried to override custom/modules/Leads/views/view.edit.php

i’ve added calls to get role and group and if conditions are found, i return echo “js code to select value” and finally call to parent::display() and it’s working :smiley:

i’m going to watch your links anymays , thank you again :slight_smile:

1 Like