How do you mark a Lead converted on record.js ?

Hello there !

What i want :

On Pro 7.5.2

For a client, when a user clicks on a custom button in a Leads' record, it calls an external API.
So, basically, i want that, if the api call is successful and we don't get any errors, i want to disable  editing on the Leads' record, and i want to mark it as "converted". (aka, get the convert button to turn green, and save the fact that the lead has been converted into the databases)


What i did :
I've managed to do this with the 
app.api.call('GET', app.api.buildURL('myCustomEndPoint/myCustomMethod/'+this.model.get('id')), null, { 
    success: function(date) {
        console.debug("Success!");
        var acls = app.user.getAcls();
        acls.Leads.edit = 'no'; 
        app.user.set("acls", acls);
        self.model.set('converted','1');
        /*$('[name="edit_button"]').hide(); */
    },
    error:function(error){
        console.debug(error);
    }
});


Where i am stuck :

For the "disable edit" part,  i tried to change the ACL on it -as you can see, but it does not seem to work. Do you have any idea on this?
But, well, this is not the most important question i have (really, because i can hide the "edit" button if i want to).

The most important question here is :

- How to mark the lead as Converted ? Aka : Being on record.js, how can i fill the database column "converted" with 1, and render the green button saying "Converted"

As you can see, i've tried with

this.model.set('converted','1');

but in the Firebug Console, it says that "this" is undefined, so i tried with declaring self = this before the api call. But it does not work either.


I would like it to change from 0 to 1 and to be saved in databases...

Thanks a lot for the ideas and the tips !
Parents Reply Children
  • Hi Gaelle

    I am just updating my previous code here. I checked from my end and I could achieve this just by overrideing the method instead of completing rewriting in the custom record view controller. Please add the below code to your custom record.js file

    _buildGridsFromPanelsMetadata:function(panels){
      this._super('_buildGridsFromPanelsMetadata',[panels]);
      _.each(panels, function(panel) {
       _.each(panel.fields, function(field, index) {
    //if the lead is converted we will push all the fields to noEditFields array.
      if(this.model.get('converted')){
           this.noEditFields.push(field.name);
      }
      },this);
      }, this);
      },
    
  • The above method is taken from the standard record.js file. If you push any fields to the noEditFields array, it will become non-editable.

    So along with the conditions based on acls we are just adding a new condition which will check the lead is converted or not. If it is converted each fields will be added to the noEditFields array.

    1. else if(this.model.get('converted') == true){ 
    2.   this.noEditFields.push(field.name); 

                             }