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

  • For fully custom modules (which sadly are not actually upgrade safe as there is nothing to stop Sugar using your module name in the future and having a clash apart from the prefix that is added by Module Builder!) I only ever use the vardefs.php and appropriate language files in the module directory for creating new fields. New fields in custom modules always go onto the main table.

    In fact, we generally have a team rule that we put updates to our own modules into the main directory. That applies to views and layouts as well. We tend to avoid using Studio for layout changes so don't need to worry about the files going into the custom tree. That way we can use source control and CI tools to manage the files from afar. And we know when a customer has been fiddling with things Slight smile

    As you say, we all learn every day.

    Thanks,

    JH.

  • There are many things I would do differently now compared to what we did in the last decade. I'm trying to clean some things, but it's not easy to "back out" of older code/decisions, especially when there are multiple external integrations.

    Sadly, sometimes it's easier to live with those poor choices.