SugarCRM readonly custom field based on user role

A few days ago I responded to a question on stackoverflow.com about creating a custom field that is rendered read-only to users who have a particular role. The realization of this behavior on the commercial versions of SugarCRM is almost trivial but it is not on the Community Edition.

We want to add a custom field of type checkbox called Processor SignOff on the Task module of SugarCRM and want to make read-only access to this field to members of the role ITOperation. The field must be available on the layout of edit-view. To easily reach the goal, proceed as follows:

  1. Step 1: Create the custom field of type checkbox from the Studio environment;
  2. Step 2: Create or edit the metadata of the edit view of where editviewdefs.php indicate how to render the new custom field;
  3. Step 3: Create or edit SugarView::display() to make sure that the smarty template is possible to know when to display the custom field read-only or not.

Listing 1 shows the code snippet of editviewdefs.php responsible for rendering the control on the form editing Task module, and Listing 2 shows the extent of the method SugarView::display() that retrieves the user’s role and sets the variables for the Smarty Template.

Listing 1. Code fragment of the definition of the custom field.

Listing 2. Implementation of the method SugarView::display()

This customization should be done in safe mode so the two files affected by the change will be on the custom directory and exactly:

  1. File metadata edit view in custom/modules/Tasks/metadata/editviewdefs.php;
  2. Class file SugarView view.edit.php in custom/modules/Tasks/views/view.edit.php

To apply the new customization just make a nice and Quick Repair and your new custom field based on role is done.

Enhanced by Zemanta
Liferay Portal Security AuditCos'è e come funzione il framework di Security Audit

Vi siete mai chiesti cos'è e come funziona il sistema di Security Audit di Liferay? Ho cercato di rispondere alla domanda non soffermandomi solo al "cosè e come funziona", sono andato ben oltre. Non vi resta che leggere questo EBook per scoprire.

Ottieni il tuo EBook

Antonio Musarra

I began my journey into the world of computing from an Olivetti M24 PC (http://it.wikipedia.org/wiki/Olivetti_M24) bought by my father for his work. Day after day, quickly taking control until … Now doing business consulting for projects in the enterprise application development using web-oriented technologies such as J2EE, Web Services, ESB, TIBCO, PHP.

You may also like...

Liferay SSL/TLS SecurityCome configurare il bundle Liferay per abilitare il protocollo SSL/TLS

Sei curioso di scoprire come configurare il bundle Liferay per funzionare in modalità sicura tramite protocollo SSL/TLS? In questo eBook ( #LFRDEPGUIDE ) ti spiego come farlo step-by-step; per il bundle Apache Tomcat e WildFly. Ricorda di lasciare un tuo feedback dopo averlo letto.