How to add a related Field without adding an explicit relationship?

Hi Developer,

In SugarCRM Studio I can add a field with the type relate and link to the Accounts module. There should not be an explicit relationship between the modules. A custom table is then created for this, in which the ID of the account is inserted. So fine, so good.
However, I would like the field to be created via a vardef and the information to be directly in the original table. The question is: How do I have to knit the vardef so that the ID of the account appears directly in the SQL table of the module, but the name of the linked account is displayed on the user interface in the layout?

The documentation at support.sugarcrm.com/.../vardefs does not provide any revealing information.

Our current status looks like this: We want to implement the DIS field in the Purchased Line Items module:

$dictionary['PurchasedLineItem']['fields']['DIS'] = array(
    'name' => 'DIS',
    'vname' => 'LBL_DIS',
    'type' => 'relate',
    'rname' => 'name',
    'id_name' => 'id',
    'module' => 'Accounts',
    'comment' => 'The name of the account represented by the account_id field',
    'required' => false,
    'studio' => true,
);

But that doesn't work. The field is displayed, but cannot be used. The ID of the purchased line item is always entered. Selecting the accounts works, but there is an error when saving, the account is not written to the data record. The sugarcrm log remains empty.

Thank you for your support.

Kind regards.

Martin

Parents Reply Children
  • Hi  ,

    I'm sorry if it didn't fix right away. There could be many reasons for it. I noticed that you didn't present source field.
    Following code block created the field sac_c in the Cases module on my local instance. You can give a try and validate. Please remember to add the sac_c field to the record view as well. 

    <?php
    $dictionary['Case']['fields']['sac_c'] = array(
        'name' => 'sac_c',
        'vname' => 'Contact',
        'type' => 'relate',
        'rname' => 'name',
        'id_name' => 'id',
        'module' => 'Contacts',
        'table' => 'contacts',
        'comment' => '',
        'required' => false,
        'studio' => true,
        'source' => 'custom_fields',
    );


    Note: Comparing to Harald's example this definitions does not need link field definitions. 

    Tevfik Tümer
    Sr. Developer Support Engineer