Create call via js

Hi,

I have function to create call via js in phone.js but it didn't work.

I saw in network tab wait for about 1 or 2 minutes then it return all my 20 calls, not create a new one.

Can anyone help me to fix my code?

// this.getPID is case id
closeClicked: function(event) {
        console.log(this.getPID);
        App.api.call('POST', App.api.buildURL('Calls'), {
            "name":"Test",
            "parent_id" : this.getPID,
            "parent_type" : "Cases"
        }, {
            success: function (data) {
                console.log(data);
            },
            error: function (e) {
                throw e;
            }
        });
    },

Sugar Ent 7.7

Thanks,

M

Parents
  • Hi Autchara Chaiprom,

    Try this:

    // this.getPID is case id
    closeClicked: function(event) {
            console.log(this.getPID);
            var self = this;
            App.api.call('create', App.api.buildURL('Calls'), {
                "name":"Test",
                "parent_id" : self.getPID,
                "parent_type" : "Cases"
            }, {
                success: function (data) {
                    console.log(data);
                },
                error: function (e) {
                    throw e;
                }
            });
        },

    Note 1: I've changed the POST in App.api.call and put create

    Note 2: You should not call this.* inside an API call; first you should save your this object in other object (ex. self) and use that instead.

    Regards,

    David.

Reply
  • Hi Autchara Chaiprom,

    Try this:

    // this.getPID is case id
    closeClicked: function(event) {
            console.log(this.getPID);
            var self = this;
            App.api.call('create', App.api.buildURL('Calls'), {
                "name":"Test",
                "parent_id" : self.getPID,
                "parent_type" : "Cases"
            }, {
                success: function (data) {
                    console.log(data);
                },
                error: function (e) {
                    throw e;
                }
            });
        },

    Note 1: I've changed the POST in App.api.call and put create

    Note 2: You should not call this.* inside an API call; first you should save your this object in other object (ex. self) and use that instead.

    Regards,

    David.

Children