15
August

0 Comments | 0 Shares | Urdhva Tech | Tags: ReadOnly Field

Greetings from Urdhva Tech!!

I came across an interesting question today on Forum, which raised my eyebrow and led me to implement and write a blog!

So, here we go!!

AIM: Make Work Phone read-only of a Contact for certain role users!

Step 1: As it is SugarCRM's module, copy modules/Contacts/views/view.edit.php to custom/modules/Contacts/views/view.edit.php or edit if it already exists at custom/modules/Contacts/views/view.edit.php

In function display() add following piece.

function display() { // add this if function display doesn't exist  
                global $current_user;
                // check if current user is in specific role
                // code taken from thread
                $IS_AM = in_array("<ROLE NAME>", ACLRole::getUserRoleNames($current_user->id));
                if($IS_AM)
                    $this->ev->ss->assign('readOnly', 'readonly = "readonly"');
                else
                    $this->ev->ss->assign('readOnly', '');

                parent::display(); // add this if function display doesn't exist 
} // add this if function display doesn't exist


Step 2: Open custom/modules/Contacts/metadata/editviewdefs.php, if doesn't exist, go to Studio > Contacts > Layouts > Edit View and press Save and Deploy.

Give custom code to the field, phone_work,

'customCode' => '<input type="text" class="phone" tabindex="0" title="" value="{$fields.phone_work.value}" maxlength="100" size="30" id="phone_work" name="phone_work" {$readOnly}>',


Repeat step 2, for Quick Create.

Do Quick Repair and rebuild! See it working smoothly, every time!!!

If you wish this to happen only while editing a record, add a condition to if($IS_AM && !empty($this->bean->id))

 

Download attachments:
Comments
  • No Comments Found.
Post your comment