Easily Retrieve All Field Information in SugarCRM with a Browser Console Script

As a technical support engineer for SugarCRM, I often need to see specific field values for a record. But fields can sometimes be hidden from the Record View or even missing from the layout entirely. Additionally, knowing just the field name (rather than the display label) often requires extra steps. Normally, you’d have to go into Studio to locate the field in the layout or find its display label, then return to the Record View to track it down. This back-and-forth can be time-consuming, especially with complex layouts or multiple fields.

To make this easier, I created a JavaScript script that runs directly in the browser console while viewing a record. With one click, this script pulls all fields for the current record and displays each field’s name, display label, and value in an organized table, so you have everything you need right at your fingertips.

The Script

Here’s the JavaScript code that retrieves and displays the field information:

javascript:(function() {
    console.clear();

    // Check if we're in the correct context to run the script
    if (App && App.controller && App.controller.context && App.controller.context.get('model')) {

        // Retrieve model and field information
        let model = App.controller.context.get('model');
        let fields = model.fields;
        let recordData = model.attributes;
        let output = [];

        // Loop through each field in the model
        for (let field in fields) {
            if (fields.hasOwnProperty(field)) {
                let fieldName = field;
                let label = App.lang.get(fields[field].vname, model.module) || fieldName;
                let value = recordData[fieldName];

                // If value is an array, format it for display
                if (Array.isArray(value)) {
                    value = value.map(function(item) {
                        if (typeof item === 'object' && item !== null) {
                            return item.email_address || item.name || JSON.stringify(item);
                        }
                        return item;
                    }).join(', ');
                }

                // Add the formatted field to the output array
                output.push({
                    'Label': label,
                    'Field Name': fieldName,
                    'Value': value
                });
            }
        }

        // Sort output by label for readability
        output.sort(function(a, b) {
            return a.Label.localeCompare(b.Label);
        });

        // Display the results in a table format
        console.table(output);
    } else {
        console.error('This script must be run in the record view context.');
    }
})();

Using the Bookmarklet

To make accessing this script easier, I turned it into a bookmarklet. A bookmarklet allows you to run JavaScript with a single click by saving it as a bookmark in your browser. Once set up, you can retrieve all field information with a quick click, avoiding the need to re-paste code.

Here’s how you can create and use this bookmarklet:

  1. Copy the code below:

javascript:(function(){console.clear();if(App&&App.controller&&App.controller.context&&App.controller.context.get('model')){let model=App.controller.context.get('model');let fields=model.fields;let recordData=model.attributes;let output=[];for(let field in fields){if(fields.hasOwnProperty(field)){let fieldName=field;let label=App.lang.get(fields[field].vname,model.module)||fieldName;let value=recordData[fieldName];if(Array.isArray(value)){value=value.map(function(item){if(typeof item==='object'&&item!==null){return item.email_address||item.name||JSON.stringify(item);}return item;}).join(', ');}output.push({'Label':label,'Field Name':fieldName,'Value':value});}}output.sort(function(a,b){return a.Label.localeCompare(b.Label);});console.table(output);}else{console.error('This script must be run in the record view context.');}})();

  1. In your browser, go to your bookmarks and select “Add New Bookmark” (the wording may vary depending on the browser).
  2. In the URL field, paste the code you copied. Then, name your bookmark something recognizable, like Show SugarCRM Fields.
  3. Save the bookmark.

How to Use the Bookmarklet

  1. Open the record in SugarCRM where you want to view all field information.
  2. Open your browser console (usually accessed via F12 or right-clicking to "Inspect Element," then navigating to the Console tab).
  3. Click the Show SugarCRM Fields bookmark you created, and the script will automatically display a table in the console with each field’s display label, field name, and current value for that record.

This script provides a complete snapshot of all fields, regardless of whether they are in the visible layout, allowing you to troubleshoot quickly and accurately.

Feel free to try it out, and I hope it helps simplify your work with SugarCRM as much as it has for me. Happy troubleshooting!

  •  

    Very nice and useful, thank you very much.

    Keep 'em coming Smiley

  • WOW! Great tool! Thanks for sharing  !

    This is a great time-saver!

    This will come in particularly handy for non-sugar developers who are building integrations from other tools and passing the wrong dropdown value.

    The value is set in the DB but they can't see it in the interface because there is no corresponding label.

    Instead of wondering why it is not being set they can quickly see that the value is there, just not displayed, and can contact me to double check whether the value needs to be added to the dropdown or they need to use a different one.


    FrancescaS

  • This IS a great time-saver !!
    Thank you Dustin Pray
    Very useful.

  • Hi  ,

    This is a helpful tip! My process for viewing all field data was using a more manual script that requires the module name and ID:

    App.api.call('read', App.api.buildURL('<module_name>/<guid>'));

    I was attempting to use your script today but I was not getting accurate results. I created a new checkbox field and date field. The date field's value was calculated based on whether the checkbox was flagged or not. After creating the fields, I mass updated a subset of records in the module to trigger the corresponding calculation. At first your script was showing the checkbox field value as 'true' but the date field was showing as 'undefined'. I was confused as to why the date value wasn't populated since I was using a simple ifElse formula. After changing the formula a few times, all of the sudden the checkbox value started reporting as 'undefined' as well which didn't make any sense since that value was manually set. I checked other records and all showed the same results.

    That was when I went back to my console command above and confirmed that both fields did in fact have a value populated. I confirmed the record ID reported in your script matched the ID used in mine, so I'm not sure why your script wasn't pulling back the appropriate values.

    Do you have any thoughts on why the script would not pull back accurate results for a record?

    Chris

  • Hi  ,

    After looking at this with  , he pointed out that your script is pulling field values from the controller model which means it will only pull fields necessary for rendering the record view (i.e. fields displayed and fields used in displayed, calculated fields). In my example, I created the fields but didn't add them to the record view so their values were not consistently pulled in through that model. In some unrelated testing, I saw where a hidden calculated dropdown field would often return the incorrect value or an undefined value in the controller model your script retrieves. The API call that I use performs an unfiltered query for that record's data so there are no limitations and explains the discrepancy I observed between the two methods.

    Using your concept, Jerry updated the script to perform the API call and present all of the record's field data in an easy to read format:

    let model = App.controller.context.get('model');
    let module = model?.module ?? model.get('_module');
    let fieldsMeta = App.metadata.getModule(module).fields;
    
    App.api.call(
        'read',
        App.api.buildURL(module + '/' + model.get('id') + '?fields=' + Object.keys(fieldsMeta)), {
    
        }, {
            success: function(recordData) {
                let output = [];
              
                // Loop through each field in the result
                for (let field in recordData) {
                    let fieldName = field;
    
                    let label = App.lang.get(fieldsMeta[field]?.vname ?? fieldsMeta[field]?.label, module) || fieldName;
                    let value = recordData[fieldName];
    
                    // If value is an array, format it for display
                    if (Array.isArray(value)) {
                        value = value.map(function(item) {
                            if (typeof item === 'object' && item !== null) {
                                return item.email_address || item.name || JSON.stringify(item);
                            }
                            return item;
                        }).join(', ');
                    } else if (_.isObject(value)) {
                        value = JSON.stringify(value)
                    }
    
                    // Add the formatted field to the output array
                    output.push({
                        'Label': label,
                        'Field Name': fieldName,
                        'Value': value
                    })
                }
    
                // Sort output by label for readability
                output.sort(function(a, b) {
                    return a.Label.localeCompare(b.Label);
                });
    
                // Display the results in a table format
                console.table(output);
            }
        }
    );

    Here is the code I used for the bookmarklet:

    javascript:(function(){console.clear();let model = App.controller.context.get('model');let module = model?.module ?? model.get(%27_module%27);let fieldsMeta = App.metadata.getModule(module).fields;App.api.call(%27read%27,App.api.buildURL(module + %27/%27 + model.get(%27id%27) + %27?fields=%27 + Object.keys(fieldsMeta)),{}, {success: function(recordData) {let output = [];for (let field in recordData) {let fieldName = field;let label = App.lang.get(fieldsMeta[field]?.vname ?? fieldsMeta[field]?.label, module) || fieldName;let value = recordData[fieldName];if (Array.isArray(value)) {value = value.map(function(item) {if (typeof item === %27object%27 && item !== null) {return item.email_address || item.name || JSON.stringify(item);}return item;}).join(%27, %27);} else if (_.isObject(value)) {value = JSON.stringify(value)}output.push({%27Label%27: label,%27Field Name%27: fieldName,%27Value%27: value})}output.sort(function(a, b) {return a.Label.localeCompare(b.Label);});console.table(output);}});})();

    Thanks again for posting this tip!

    Chris

  •    Am I correct in saying you dont need to save this javascript on the CRM directory anywere, just run at browser level?

  •  , Yes, that is correct. You can store it as a bookmark per  's example or use it directly in your browsers console.