ID Fields in Studio

July 27, 2022
Jerry Clark

The following snippet will outline how to add an ID field to a module in Studio in SugarCRM.

Swagger

The Basics

To enable the ID field, we need to create a vardef extension updating the fields studio property to true.

//enable the id field in studio
$dictionary['{module}']['fields']['id']['studio'] = true;

As we also want to prevent users from editing the id field, let's make the field read-only and hide it on the create views:

//default the fields view properties
$dictionary['{module}']['fields']['id']['displayParams'] = [
    //make sure this field is readonly
    'readonly' => true,
    //hide the id on create views
    'dependency' => 'greaterThan(strlen($id),0)'
];

Example

If you are working on a local instance, you can implement this customization for Accounts as follows:

./custom/Extension/modules/Accounts/Ext/Vardefs/AddIdToStudio.php

<?php

//enable the id field in studio
$dictionary['Account']['fields']['id']['studio'] = true;

//default the fields view properties
$dictionary['Account']['fields']['id']['displayParams'] = [
    //make sure this field is readonly
    'readonly' => true,
    //hide the id on create views
    'dependency' => 'greaterThan(strlen($id),0)'
];

Next, navigate to Admin > Repairs > Quick Repair and Rebuild. The ID field will now be available on the Accounts record view.

Download

You can download the module loadable package below for testing purposes.

  • Sugar Versions: 12.x
  • License: Open-Source (Apache 2.0)

Are you new to Sugar? Start a free trial today.

Please follow us on social media or subscribe to our RSS feed to keep up-to-date on new blog posts and announcements:

To read more about our company and services, please visit our home page.