SugarCRM 7 - Conditional Read Only Fields

Posted on Sat 06 February 2016 in SugarCRM

SugarCRM has a few ways to set fields as read-only, but it leaves a lot to be desired. One of the missing features that you might need to implement is having a module flagged as read-only on the record view based on a field on the module or the result of an API request.

I have found a way to do it but it is mostly basic UI hacking and doesn't set the field read-only everywhere on the UI, just the record view page. So it will remain on the recordlist view or within other subpanels as editable, so bear this in mind as it's only useful for very specific cases.

Here's a quick javascript function that'll iterate over all sidecar metadata panels and flag every field on the UI. Simply add in a conditional to flag only certain fields and wrap it in whatever checks you need to make. Stick this in your record.js.

setReadOnly: function() {
    if(this.readOnly) {
        // set fields to read-only
        _.each(this.meta.panels, function(panel) {
            _.each(panel.fields, function(field) {