SugarCRM: Create button on the detail view

To create a custom button on the detail view of a module {MODULE_NAME} use the below code

Create a file or modify the below file custom/modules/{MODULE_NAME}/views/view.detail.php

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 
require_once('include/json_config.php'); 
require_once('include/MVC/View/views/view.detail.php'); 
require_once('custom/include/general_functions.php');
class {MODULE_NAME}ViewDetail extends ViewDetail
{
    function {MODULE_NAME}ViewDetail()
    {
        parent::ViewDetail();
    }
    function display()
    {
        $this->dv->defs['templateMeta']['form']['buttons'][101] = array (
            'customCode' => '<input title="Custom Text Here" accesskey="{$APP.LBL_PRINT_PDF_BUTTON_KEY}" class="button" onClick="javascript:CustomFunctionHere();" name="tckpdf" value="Custom Text Here" type="button">');
        parent::display();
    }
}
?>
SugarCRM: Create button on the detail view

SugarCRM: listview link for relate field

Open the file custom/modules/KEY_Module1/metadata/listviewdef.php

Replace the particualr field array with the below line

'FIELD_C' => 
  array (
    'type' => 'relate',
    'link' => 'key_module1_key_module2',
    'module' => 'KEY_Module1',
    'id' => 'FIELDNAME_C',
    'default' => true,
    'studio' => 'visible',
    'label' => 'LBL_FIELD',
    'width' => '10%',
    'related_fields' => array('fieldname_c'),  
),
SugarCRM: listview link for relate field

SugarCRM: On import field type int with validation range not working

Issue found on the SugarCRM Professional 6.1.2

Edit the file modules/Import/ImportFieldSanitize.php

Replace the function int with the below code

/**
 * Validate int fields
 *
 * @param  $value  string
 * @param  $vardef array
 * @return string sanitized and validated value on success, bool false on failure
 */
public function int(
    $value,
    $vardef
    )
{
    $value = str_replace($this->num_grp_sep,"",$value);
    if (!is_numeric($value) || strstr($value,".")) {
        return false;
    }
    if (isset($vardef['validation']) && $vardef['validation']['type']=='range') {
        $min    = $vardef['validation']['min'];
        $max    = $vardef['validation']['max'];
        if ($value$max) {
            return false;
        }
    }
    return $value;
}
SugarCRM: On import field type int with validation range not working

SugarCRM: retrieve a record ID using name and other fields

Use the function retrieve_by_string_fields to retrieve a record using multiple search filters.
See Example below:

$call = new Call();
$call->retrieve_by_string_fields(array('name'=>'NAMETOSEARCH','deleted'=>0,'assigned_user_id'=>'USER_ID'));
echo $call->description;

SugarCRM: retrieve a record ID using name and other fields

SugarCRM: HTML tags on report chart labels when using Relate fields

Go to line number 289 of the file include/SugarCharts/SugarChart.php and replace the line

return $this->tab("".htmlspecialchars($value,ENT_QUOTES)."",$depth);

with

return $this->tab("".htmlspecialchars(strip_tags($value),ENT_QUOTES)."",$depth);

SugarCRM: HTML tags on report chart labels when using Relate fields

SugarCRM: Add custom module to Related To drop-down

Create a new file custom/Extension/application/Ext/Language/.lang.ext.php with the following line of code.

$app_list_strings['parent_type_display']['<MODULE_NAME>'] = '<MODULE TITLE>';
$app_list_strings['record_type_display']['<MODULE_NAME>'] = '<MODULE TITLE>';
$app_list_strings['record_type_display_notes']['<MODULE_NAME>'] = '<MODULE TITLE>';

The drop-down on Leads, Calls, Meetings, Notes, Tasks module will be changed.

SugarCRM: Add custom module to Related To drop-down

SugarCRM: include javascript file on listview

  • Create a new file on /custom/modules/<ModuleName>/views/view.list.php
  • Copy the code below

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/MVC/View/views/view.list.php');
class {ModuleName}ViewList extends ViewList
{
    function __construct()
    {
        parent::__construct();
    }
    function preDisplay()
    {
        echo '<script type="text/javascript" src="{INCLUDE_FILE_PATH}"></script>';
        parent::preDisplay();
    }
}
?>

SugarCRM: include javascript file on listview

SugarCRM: remove buttons from the subpanels

Create a file on custom/modules/{ModuleName}/views/view.detail.php

Add the below codes:

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/json_config.php');
require_once('include/MVC/View/views/view.detail.php');

class {ModuleName}ViewDetail extends ViewDetail {

    function {ModuleName}ViewDetail()
    {
        parent::ViewDetail();
    }

    /**
     * Replaces all the buttons on the subpanels
     */
    function _displaySubPanels()
    {
	require_once ('include/SubPanel/SubPanelTiles.php');
	$subpanel = new SubPanelTiles($this->bean, $this->module);
	unset($subpanel->subpanel_definitions->layout_defs['subpanel_setup']['']['top_buttons'][0]);
	unset($subpanel->subpanel_definitions->layout_defs['subpanel_setup']['']['top_buttons'][1]);
	echo $subpanel->display();
    }
}
?>

SugarCRM: remove buttons from the subpanels

SugarCRM: remove edit button on list view

Create a file called view.list.php at location “custom/modules/{ModuleName}/views/view.list.php”

Copy the contents here below

<?php
require_once('include/json_config.php');
require_once('include/MVC/View/views/view.list.php');
class {ModuleName}ViewList extends ViewList 
{
    function {ModuleName}ViewList()
    {
        parent::ViewList();
    }
    function Display()
    {
        $this->lv->quickViewLinks = false;
        parent::Display();
    }
}
?>
SugarCRM: remove edit button on list view