Creating a custom field that references the users dropdown

From SugarCRM Wiki

Jump to: navigation, search

Create a new custom field using the studio layout editor in modules/MODULE_NAME/EditView.html

 Field Name: DBFIELDNAME (Choose a field name and use that in the rest of the instructions where you see DBFIELDNAME)
 Field Label: DBFIELDLABEL (Choose a field label and use that in the rest of the instructions where you see DBFIELDLABEL)
 Data Type: text
 Max Size: 100


You'll see the two items in the staging area. Drag the label {MOD.DBFIELDLABEL__c} and the dropdown menu over to the desired location on the page. Click Save Layout.


Go edit the layout of the modules/MODULE_NAME/DetailView.html and drag those items over from the Sugar Fields on the left. Click Save Layout.

Make the following changes in the following files

in <sugarroot>/modules/MODULE_NAME/MODULE_NAME.php:

 function fill_in_additional_detail_fields()
 {
   // Fill in the assigned_user_name
   $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
   	
   //CUSTOM CODE BEGIN
   $this->DBFIELDNAME_c_name = get_assigned_user_name($this->DBFIELDNAME_c);
   //CUSTOM CODE END
   
   $this->assigned_name = get_assigned_team_name($this->team_id);


in <sugarroot>/modules/MODULE_NAME/DetailView.php:

 // adding custom fields:
 require_once('modules/DynamicFields/templates/Files/DetailView.php');
 
 //CUSTOM CODE BEGIN
 $xtpl->assign("DBFIELDNAME_C", $focus->DBFIELDNAME_c_name);
 //CUSTOM CODE END


in <sugarroot>/modules/MODULE_NAME/EditView.php

 if (empty($focus->assigned_name) && empty($focus->id))  $focus->assigned_user_name = $current_user->user_name;
 $xtpl->assign("ASSIGNED_USER_OPTIONS", get_select_options_with_id(get_user_array(TRUE, "Active", $focus->assigned_user_id), $focus->assigned_user_id));
 
 //CUSTOM CODE BEGIN
 $xtpl->assign("DBFIELDNAME_OPTIONS", get_select_options_with_id(get_user_array(), $focus->DBFIELDNAME_c));
 //CUSTOM CODE END


in <sugarroot>/modules/MODULE_NAME/EditView.html (item should already exist below)

 class="dataLabel"><slot>{MOD.DBFIELDLABEL__c}</slot>
 class="dataField"><slot><select name="DBFIELDNAME_c">{BLAHBLAH}</select></slot>
 to
 class="dataLabel"><slot>{MOD.DBFIELDLABEL__c}</slot>
 class="dataField"><slot><select name="DBFIELDNAME_c">{DBFIELDNAME_OPTIONS}</select></slot>


That should do it

Personal tools