Relate field to 'Employees' module

Hi,

I have built a custom module using module builder and have deployed to a Sugar instance.

I want to add a Relate field in the custom module which links to the Employees module. This is because the information to be captured can relate to either ex-staff, or indeed staff who are not users of the CRM application and I would like a field which exposes the Employee records.

I found this external post from 2011 but it refers to Sugar 6x and I'm not sure how to map this to the current Sugar framework.

Thanks

Neil

Angel's Blog: SugarCRM Customization: Employees Relate Field 

Parents Reply Children
  • Hi Andres Lopez

    I've been away from this for a few weeks and now back on it. Must admit, still struggling a bit.

    Managed to get the endpoint e-num piece working so that the field now surfaces a list of the employees when I am creating/editing the record. However, when I save the record, the chosen value does not get saved into the record, it remains empty.

    Would welcome your advice.

    Thanks

    Here is my vardefs file (based on Angel blog)

    Notes :

    1. Commented out the original type => relate as type from your guidance is 'enum-api'
    2. When I ran the QRR after adding this vardef file , was prompted to create field and this added field sym_employeenew_id_c to the module table in the SQL database
    3. In Studio I see the field and its name shows as sym_employee_c with type Enum-api

    This is the vardefs file

    <?php

    $dictionary["symfc_FCQuotas"]["fields"]["sym_employee_c"] = array (
    'required' => false,
    'source' => 'non-db',
    'name' => 'sym_employee_c',
    'vname' => 'Employee',
    //'type' => 'relate',
    'type' => 'enum-api',
    'api' => 'Employees/employees_list/',
    'massupdate' => 0,
    'comments' => '',
    'help' => '',
    'importable' => 'true',
    'duplicate_merge' => 'disabled',
    'duplicate_merge_dom_value' => '0',
    'audited' => false,
    'reportable' => true,
    'calculated' => false,
    'len' => '255',
    'size' => '20',
    'id_name' => 'sym_employeenew_id_c',
    'ext2' => 'Employees',
    'module' => 'Employees',
    'rname' => 'name',
    'quicksearch' => 'enabled',
    'studio' => 'visible',

    );

    $dictionary["symfc_FCQuotas"]["fields"]["sym_employeenew_id_c"] = array (
    'required' => false,
    'name' => 'sym_employeenew_id_c',
    'vname' => '',
    'type' => 'id',
    'massupdate' => 0,
    'comments' => '',
    'help' => '',
    'importable' => 'true',
    'duplicate_merge' => 'disabled',
    'duplicate_merge_dom_value' => 0,
    'audited' => false,
    'reportable' => true,
    'calculated' => false,
    'len' => 36,
    'size' => '20',
    );


    ?>

    This is the api.php file which populates the DD list 

    <?php
    class symEmployeesApi extends SugarApi
    {
    public function registerApiRest()
    {
    return array(
    'getEmployeeList' => array(
    'reqType' => 'GET',
    'path' => array('Employees', 'employees_list'),
    'pathVars' => array(),
    'method' => 'getEmployeeList',
    'shortHelp' => 'Get a list employees for a dropdown field',
    'longHelp' => '',
    ),
    );
    }

    public function getEmployeeList($api, $args)
    {
    $list = array('' => $GLOBALS['app_strings']['LBL_NONE']);
    $query = new SugarQuery();
    $query->select(array('id', 'name'));
    $query->from(BeanFactory::getBean('Employees'));
    // $query->where()->equals('active', '1');
    $query->orderBy('sym_reportname_c', 'ASC');
    $results = $query->execute();

    foreach($results as $item) $list[$item['id']] = $item['first_name'] . ' ' . $item['last_name'];
    return $list;
    }
    }

    This the the custom module table in SQL showing no data in the field

    NULL fields

    This is the field showing in Studio

    Field in Studio