How to create a popup depending on a status?

Dear community,

I have not yet found what I am looking for and therefore I ask the question at this point:

We have implemented a status field in the Accounts module. There are two statuses (active and idle). We would like a popup to appear when an idle account is opened. This popup should looks like a warning message, contains a text and an OK button.

An example is attached.
Ho can we create such a popup? At first, we only need this Popup, which inly informs the user, that the status is idle.

Many thanks in advance for your support.

Greetings from Berlin, Germany

Martin

  • To do this, you will need to make a slight customization to the record.js controller file for that module.

    If it doesn't already exist, create the following file:

    <your sugar folder>/custom/modules/Accounts/clients/base/views/record/record.js

    And then you can extend it with your custom function to display some alert or popup when the record view loads the data.

    ({
        extendsFrom: 'RecordView',
        initialize: function (options) {
            this._super('initialize', [options]);
            this.listenTo(this.collection, 'data:sync:complete', this.renameThisFunction);  
            //this function will run once the data has been loaded into the view, so basically, this is the point in time when you want the popup to appear
        },

    renameThisFunction: function() {
        var model = app.controller.context.get('model');
        //you can then get your custom field from the model
        var yourCustomDataField = model.get('your_custom_data_field_c');
        //this will only work if the vardefs
        //and the fields_meta_data table entry have been set up correctly!
        
        if(yourCustomDataField === 'idle') {
            app.alert.show('add_unique_message_id_here', {
                level: 'error',
                messages: 'Your Error message here',
                autoClose: false
            });

        }
    }

    })

    Although this way you won't have an OK button, just an X to close as it is just an alert.

    If you need a fancier pop-up, with high customizability instead of the standard alert, you could use the Base Edit Modal View instead.

  • Hi Viktor,

    many thanks for the quick response.
    We'll check this asap. I'll give you feedback.

    Kind regards.

    Martin

  • Hi Martin,

    You can add the validation in record.js as suggested by Victor and it works. To know more about the Alerts and Adding field validations in SugarCRM, please go through field validation and alerts concepts.

  • Hi Martin,

    I will propose a different approach. Instead of using a pop-up, use a combination of a calculated text field and custom CSS. 

    The calculated text field can be created using Studio and you can set its value using Sugar Logic. This gives you added flexibility to set additional text based upon other values too.

    The custom CSS will require code change but its purpose is to highlight the message so it draws user's attention. It is not a must have.

    Regards,

    Romney

  • I'd go another step further, calculated field plus HTML field so no code changes needed