SugarCRM 7 — Conditional Read Only Fields

Shane Dowling
Feb 6, 2016 · 1 min read

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.

if(this.readOnly) {
// set fields to read-only
_.each(this.meta.panels, function(panel) {
_.each(panel.fields, function(field) {
field.readonly=true;
});
});
}
},

Tech Blog

Random smattering of technical posts

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store