SugarCRM: adding custom field in subpanel

How to add custom field into subpanel? Belo is example of Contracts subpanel that is showing in Accounts module/detailview.

irst thing that needs to be done is define a new field in subpanel definition and make that field point to a class. We are edititing the following file custom/modules/Contracts/metadata/subpanels/ForAccounts.php and adding additional field fot showing with following code:

'mediaart_new_field' => array(
'vname' => 'LBL_NEW_FIELD',
'widget_class' => 'SubPanelMediaartNewField', //class name
'width' => '10%',
'custom_link_only' => true,
'displayHeaderCell' => false,
),

After we have added that part of code we need to create coresponding SugarWidgetSubPanel class in the following path
/include/generic/Sugarwidgets/SugarWidgetSubPanelMediaartNewField.php with code like this:

<?php if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/generic/SugarWidgets/SugarWidgetField.php');
class SugarWidgetSubPanelMediaartNewField extends SugarWidgetField //payattention to the name of class here
{

function displayHeaderCell(&$layout_def){
if(!empty($layout_def['displayHeaderCell']) && $layout_def['displayHeaderCell'] == false) {
return ' ';
}
else {
return parent::displayHeaderCell($layout_def);
}
}

function displayList(&$layout_def){
global $focus;
if(isset($layout_def['varname']))
{
$key = strtoupper($layout_def['varname']);
}
else
{
$key = $this->_get_column_alias($layout_def);
$key = strtoupper($key);
}
//////////////////////////////////////////////////////////////////////////
// Current ProductTemplate record (in current subpanel row)
$module = $layout_def['module'];
$record = $layout_def['fields']['ID']; //id contract
$contractName = $layout_def['fields']['NAME']; //name contract

 

$parent_id=$_REQUEST['record']; //id account-a
//Here you define your logic, my quary to the database and the return from this function will be displayed in subpanel
//So for example you can do
$db = DBManagerFactory::getInstance();
$query = "SELECT * FROM contracts WHERE id = '$record' and account_id = '$parent_id'";
$result = $db->query($query, true,"greska");
$result = $db->fetchByAssoc($result);
$quantity = $result['broj_slucajeva'];
return $quantity; //value of this cariable will be shown in subpanel
}
} ?>

6 atsakymai į “SugarCRM: adding custom field in subpanel”

  1. Got it! Thanks a lot again for hpeling me out!

  2. Laba diena, mane itin suintrigavo J?siškis straipsnis! Bet noreciau paklausti ar sitame websaite man vieninteliui tinklalapio šablonas yra prastai atvaizduojamas. Gal ?ia manišk?s browserio problema ? Aš naudoju Safari… Labai laukiu administratoriaus atsakymo…

  3. I liked your article is an interesting technology
    thanks to google I found you

  4. You’ve got great insights about web programming, keep up the good work!

  5. I have tried everything to get this working with the newest version of Sugar CE 6.5…has anyone else had any luck getting custom widgets to work in this version?

    All I am able to modify with a custom widget is the table header cell and not the actual fields

Parašykite komentarą

El. pašto adresas nebus skelbiamas. Būtini laukeliai pažymėti *