{"id":2595,"date":"2013-09-09T14:50:48","date_gmt":"2013-09-09T12:50:48","guid":{"rendered":"http:\/\/www.dontesta.it\/blog\/?p=2595"},"modified":"2013-09-09T14:50:48","modified_gmt":"2013-09-09T12:50:48","slug":"sugarcrm-readonly-custom-field-based-on-user-role","status":"publish","type":"post","link":"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/","title":{"rendered":"SugarCRM readonly custom field based on user role"},"content":{"rendered":"<p><\/p>\n<p style=\"text-align: justify;\">A few days ago I responded to a question on <a title=\"Make custom field readonly based on user role\" href=\"http:\/\/stackoverflow.com\/questions\/18585612\/make-custom-field-readonly-based-on-user-role\/18592263#18592263\" target=\"_blank\">stackoverflow.com<\/a> 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 <a class=\"zem_slink\" title=\"SugarCRM\" href=\"http:\/\/sugarcrm.com\" target=\"_blank\" rel=\"homepage\">SugarCRM<\/a> is almost trivial but it is not on the <em>Community Edition.<\/em><\/p>\n<p style=\"text-align: justify;\">We want to add a custom field of type <em>checkbox<\/em> called <em>Processor SignOff<\/em> on the Task module of SugarCRM and want to make read-only access to this field to members of the role <em>ITOperation<\/em>. The field must be available on the layout of edit-view. To easily reach the goal, proceed as follows:<\/p>\n<ol>\n<li>Step 1: Create the custom field of type checkbox from the <em>Studio<\/em> environment;<\/li>\n<li>Step 2: Create or edit the metadata of the edit view of where editviewdefs.php indicate how to render the new custom field;<\/li>\n<li>Step 3: Create or edit<em> SugarView::display()<\/em> to make sure that the smarty template is possible to know when to display the custom field read-only or not.<\/li>\n<\/ol>\n<p>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 <em>SugarView::display()<\/em> that retrieves the user's role and sets the variables for the <a class=\"zem_slink\" title=\"Smarty\" href=\"http:\/\/www.smarty.net\" target=\"_blank\" rel=\"homepage\">Smarty<\/a> Template.<\/p>\n<pre class=\"lang:php decode:true\" title=\"Listato 1. Frammento di codice della definizione del campo personalizzato.\"> array (\r\n        'name' => 'processor_signoff_c',\r\n        'label' => 'LBL_PROCESSOR_SIGNOFF',\r\n        'customCode' => '<input type=\"hidden\" name=\"processor_signoff_c\" value=\"0\" \/><input id=\"processor_signoff_c\" type=\"checkbox\" checked=\"checked\" disabled=\"disabled\" name=\"processor_signoff_c\" value=\"=\" \/>',\r\n      ),<\/pre>\n<p>Listing 1. Code fragment of the definition of the custom field.<\/p>\n<pre class=\"lang:php mark:13,15,16 decode:true\" title=\"Listato 2. Implementazione del metodo SugarView::display()\">\/**\r\n * @see SugarView::display()\r\n *\/\r\npublic function display()\r\n{\r\n    if($this->ev->isDuplicate){\r\n            $this->bean->status = $this->bean->getDefaultStatus();\r\n    } \/\/if\r\n\r\n    global $current_user;\r\n\r\n    \/\/ check if current user is in specific role\r\n            $isEnabledRole = in_array(\"ITOperation\", ACLRole::getUserRoleNames($current_user->id));\r\n            if($isEnabledRole)\r\n                $this->ev->ss->assign('readOnly', 'readonly = \"readonly\"');\r\n                $this->ev->ss->assign('disabled', 'disabled');\r\n            else\r\n                $this->ev->ss->assign('readOnly', '');\r\n                $this->ev->ss->assign('disabled', 'disabled');\r\n\r\n    parent::display();\r\n}<\/pre>\n<p>Listing 2. Implementation of the method SugarView::display()<\/p>\n<p>This customization should be done in safe mode so the two files affected by the change will be on the custom directory and exactly:<\/p>\n<ol>\n<li>File metadata edit view in custom\/modules\/Tasks\/metadata\/editviewdefs.php;<\/li>\n<li>Class file SugarView view.edit.php in custom\/modules\/Tasks\/views\/view.edit.php<\/li>\n<\/ol>\n<p>To apply the new customization just make a nice and <em>Quick Repair<\/em> and your new custom field based on role is done.<\/p>\n<div class=\"zemanta-pixie\" style=\"margin-top: 10px; height: 15px;\"><a class=\"zemanta-pixie-a\" title=\"Enhanced by Zemanta\" href=\"http:\/\/www.zemanta.com\/?px\"><img decoding=\"async\" loading=\"lazy\" class=\"zemanta-pixie-img\" style=\"border: none; float: right;\" alt=\"Enhanced by Zemanta\" src=\"http:\/\/img.zemanta.com\/zemified_h.png?x-id=5b892312-5402-4a25-b4f6-a169161801a7\" \/><\/a><\/div>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>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&#46;&#46;&#46;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[490,8,29],"tags":[133,643],"class_list":["post-2595","post","type-post","status-publish","format-standard","hentry","category-blog-2","category-crm","category-sugarcrm","tag-customer-relationship-management","tag-sugarcrm"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SugarCRM readonly custom field based on user role<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SugarCRM readonly custom field based on user role\" \/>\n<meta property=\"og:description\" content=\"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&#046;&#046;&#046;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/\" \/>\n<meta property=\"og:site_name\" content=\"Antonio Musarra&#039;s Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/antoniomusarrablog\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/antoniomusarrablog\" \/>\n<meta property=\"article:published_time\" content=\"2013-09-09T12:50:48+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/img.zemanta.com\/zemified_h.png?x-id=5b892312-5402-4a25-b4f6-a169161801a7\" \/>\n<meta name=\"author\" content=\"Antonio Musarra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@antonio_musarra\" \/>\n<meta name=\"twitter:site\" content=\"@antonio_musarra\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Antonio Musarra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/\"},\"author\":{\"name\":\"Antonio Musarra\",\"@id\":\"https:\/\/www.dontesta.it\/#\/schema\/person\/0c69ed36230e1477875d6171b48b9b24\"},\"headline\":\"SugarCRM readonly custom field based on user role\",\"datePublished\":\"2013-09-09T12:50:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/\"},\"wordCount\":607,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.dontesta.it\/#\/schema\/person\/0c69ed36230e1477875d6171b48b9b24\"},\"image\":{\"@id\":\"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/img.zemanta.com\/zemified_h.png?x-id=5b892312-5402-4a25-b4f6-a169161801a7\",\"keywords\":[\"Customer relationship management\",\"SugarCRM\"],\"articleSection\":[\"Blog\",\"CRM\",\"SugarCRM\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/\",\"url\":\"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/\",\"name\":\"SugarCRM readonly custom field based on user role\",\"isPartOf\":{\"@id\":\"https:\/\/www.dontesta.it\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/img.zemanta.com\/zemified_h.png?x-id=5b892312-5402-4a25-b4f6-a169161801a7\",\"datePublished\":\"2013-09-09T12:50:48+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/#primaryimage\",\"url\":\"http:\/\/img.zemanta.com\/zemified_h.png?x-id=5b892312-5402-4a25-b4f6-a169161801a7\",\"contentUrl\":\"http:\/\/img.zemanta.com\/zemified_h.png?x-id=5b892312-5402-4a25-b4f6-a169161801a7\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.dontesta.it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SugarCRM readonly custom field based on user role\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dontesta.it\/#website\",\"url\":\"https:\/\/www.dontesta.it\/\",\"name\":\"Antonio Musarra&#039;s Blog\",\"description\":\"The ideal solution for a problem\",\"publisher\":{\"@id\":\"https:\/\/www.dontesta.it\/#\/schema\/person\/0c69ed36230e1477875d6171b48b9b24\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dontesta.it\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.dontesta.it\/#\/schema\/person\/0c69ed36230e1477875d6171b48b9b24\",\"name\":\"Antonio Musarra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dontesta.it\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.dontesta.it\/wp-content\/uploads\/2024\/06\/cropped-foto_profilo.png\",\"contentUrl\":\"https:\/\/www.dontesta.it\/wp-content\/uploads\/2024\/06\/cropped-foto_profilo.png\",\"width\":512,\"height\":512,\"caption\":\"Antonio Musarra\"},\"logo\":{\"@id\":\"https:\/\/www.dontesta.it\/#\/schema\/person\/image\/\"},\"description\":\"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 \u2026 Now doing business consulting for projects in the enterprise application development using web-oriented technologies such as J2EE, Web Services, ESB, TIBCO, PHP.\",\"sameAs\":[\"https:\/\/www.dontesta.it\",\"https:\/\/www.facebook.com\/antoniomusarrablog\",\"https:\/\/www.linkedin.com\/in\/amusarra\/\",\"https:\/\/x.com\/antonio_musarra\",\"https:\/\/www.youtube.com\/channel\/UC5D3_EtVPbZYUhrUcEK_THA\/\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SugarCRM readonly custom field based on user role","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/","og_locale":"en_US","og_type":"article","og_title":"SugarCRM readonly custom field based on user role","og_description":"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&#46;&#46;&#46;","og_url":"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/","og_site_name":"Antonio Musarra&#039;s Blog","article_publisher":"https:\/\/www.facebook.com\/antoniomusarrablog","article_author":"https:\/\/www.facebook.com\/antoniomusarrablog","article_published_time":"2013-09-09T12:50:48+00:00","og_image":[{"url":"http:\/\/img.zemanta.com\/zemified_h.png?x-id=5b892312-5402-4a25-b4f6-a169161801a7","type":"","width":"","height":""}],"author":"Antonio Musarra","twitter_card":"summary_large_image","twitter_creator":"@antonio_musarra","twitter_site":"@antonio_musarra","twitter_misc":{"Written by":"Antonio Musarra","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/#article","isPartOf":{"@id":"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/"},"author":{"name":"Antonio Musarra","@id":"https:\/\/www.dontesta.it\/#\/schema\/person\/0c69ed36230e1477875d6171b48b9b24"},"headline":"SugarCRM readonly custom field based on user role","datePublished":"2013-09-09T12:50:48+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/"},"wordCount":607,"commentCount":0,"publisher":{"@id":"https:\/\/www.dontesta.it\/#\/schema\/person\/0c69ed36230e1477875d6171b48b9b24"},"image":{"@id":"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/#primaryimage"},"thumbnailUrl":"http:\/\/img.zemanta.com\/zemified_h.png?x-id=5b892312-5402-4a25-b4f6-a169161801a7","keywords":["Customer relationship management","SugarCRM"],"articleSection":["Blog","CRM","SugarCRM"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/","url":"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/","name":"SugarCRM readonly custom field based on user role","isPartOf":{"@id":"https:\/\/www.dontesta.it\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/#primaryimage"},"image":{"@id":"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/#primaryimage"},"thumbnailUrl":"http:\/\/img.zemanta.com\/zemified_h.png?x-id=5b892312-5402-4a25-b4f6-a169161801a7","datePublished":"2013-09-09T12:50:48+00:00","breadcrumb":{"@id":"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/#primaryimage","url":"http:\/\/img.zemanta.com\/zemified_h.png?x-id=5b892312-5402-4a25-b4f6-a169161801a7","contentUrl":"http:\/\/img.zemanta.com\/zemified_h.png?x-id=5b892312-5402-4a25-b4f6-a169161801a7"},{"@type":"BreadcrumbList","@id":"https:\/\/www.dontesta.it\/en\/2013\/09\/09\/sugarcrm-readonly-custom-field-based-on-user-role\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.dontesta.it\/"},{"@type":"ListItem","position":2,"name":"SugarCRM readonly custom field based on user role"}]},{"@type":"WebSite","@id":"https:\/\/www.dontesta.it\/#website","url":"https:\/\/www.dontesta.it\/","name":"Antonio Musarra&#039;s Blog","description":"The ideal solution for a problem","publisher":{"@id":"https:\/\/www.dontesta.it\/#\/schema\/person\/0c69ed36230e1477875d6171b48b9b24"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dontesta.it\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.dontesta.it\/#\/schema\/person\/0c69ed36230e1477875d6171b48b9b24","name":"Antonio Musarra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dontesta.it\/#\/schema\/person\/image\/","url":"https:\/\/www.dontesta.it\/wp-content\/uploads\/2024\/06\/cropped-foto_profilo.png","contentUrl":"https:\/\/www.dontesta.it\/wp-content\/uploads\/2024\/06\/cropped-foto_profilo.png","width":512,"height":512,"caption":"Antonio Musarra"},"logo":{"@id":"https:\/\/www.dontesta.it\/#\/schema\/person\/image\/"},"description":"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 \u2026 Now doing business consulting for projects in the enterprise application development using web-oriented technologies such as J2EE, Web Services, ESB, TIBCO, PHP.","sameAs":["https:\/\/www.dontesta.it","https:\/\/www.facebook.com\/antoniomusarrablog","https:\/\/www.linkedin.com\/in\/amusarra\/","https:\/\/x.com\/antonio_musarra","https:\/\/www.youtube.com\/channel\/UC5D3_EtVPbZYUhrUcEK_THA\/"]}]}},"_links":{"self":[{"href":"https:\/\/www.dontesta.it\/en\/wp-json\/wp\/v2\/posts\/2595","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dontesta.it\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dontesta.it\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dontesta.it\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dontesta.it\/en\/wp-json\/wp\/v2\/comments?post=2595"}],"version-history":[{"count":0,"href":"https:\/\/www.dontesta.it\/en\/wp-json\/wp\/v2\/posts\/2595\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dontesta.it\/en\/wp-json\/wp\/v2\/media?parent=2595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dontesta.it\/en\/wp-json\/wp\/v2\/categories?post=2595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dontesta.it\/en\/wp-json\/wp\/v2\/tags?post=2595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}