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
  • Hello!

    I created my own little test button in the record view for my local 7.5.2.3 Leads module. My function simply does this:

     
    this.model.set("converted",true);  
    this.model.save();

    That seems to set the converted field in the database and adds the green "Converted" label to the record view. If this does not work for you and you are still getting the "this" is undefined, then your issue is probably more scope than the setting of the converted field. If it helps any, I followed the examples here to setup the custom button and function call.

    I hope that helps!

    -Mark
  • Hello everyone !

    I'm coming back to these little lines of code...

    It works REALLY great.

    But, to make it complete, i still have a question for you !

    How to change the ACLs on this particular converted lead to Edit = 'no' ?

    I know i can do

      var acls = app.user.getAcls();

      acls.Leads.edit = 'no';

      app.user.set("acls", acls);

    But this will unable Edit on ALL Leads. How can i specify the record i want to force to be uneditable ?

    Thanks a lot !

Reply
  • Hello everyone !

    I'm coming back to these little lines of code...

    It works REALLY great.

    But, to make it complete, i still have a question for you !

    How to change the ACLs on this particular converted lead to Edit = 'no' ?

    I know i can do

      var acls = app.user.getAcls();

      acls.Leads.edit = 'no';

      app.user.set("acls", acls);

    But this will unable Edit on ALL Leads. How can i specify the record i want to force to be uneditable ?

    Thanks a lot !

Children