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
  • Hi  ,

    The relate fields are required to have a link to be used. However, if you provide the table that can be self sufficient as well. 
    So all you need to do please add:

        'table' => 'accounts',

    So your vardef should be:
    $dictionary['PurchasedLineItem']['fields']['DIS'] = array(
        'name' => 'DIS',
        'vname' => 'LBL_DIS',
        'type' => 'relate',
        'rname' => 'name',
        'id_name' => 'id',
        'module' => 'Accounts',
        'table' => 'accounts', // Table needs to be here
        'comment' => 'The name of the account represented by the account_id field',
        'required' => false,
        'studio' => true,
    );


    Hope this helps. :) 

    Tevfik Tümer
    Sr. Developer Support Engineer

  • Hi  ,
    I tried your suggestion, but it did not bring about any changes. Thanks for your input though.
    Kind regards
    Martin

  • 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

Reply
  • 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

Children