Extension to call suitelet file to approve SO

The approver can approve the sales order from the Approver detail page. We are created a suitelet to approve and decline the sales order. The request details is added below. it is a post request so pass the details in the body When approving or rejecting an order .To request the suitelet using the service controller of SCA. To use the suitelet using SCA standard method. once the sales order is approved need to update the list and detail page of the approval without load.

In tpl file added data-action

<button class="approve-order-button remove-button" data-action="approve-order">Approve Order</button>


In view file call to service controller and passed object with post

events: {
    'click [data-action="approve-order"]': 'approveorder'
}
// @method to approve the sales order
approveorder: function approveorder() {
    var self = this;
    var transid = self.id;
    var object = {
        Action: 'Approve',
        SO_Id: transid
    }
    try {
        $('.approve-order-button').text('Processing...');
        this.ApprovalModel.save(object, {
            type: 'POST'
        }).fail(function (e) {
            var error = e.responseJSON;
            self.showError(error.errorMessage);
        }).done(function (data) {
            var success = data.successMessage;
            // Check the value of the success
            if (success == "true") {
                self.ApprovalModel.fetch({
                    data: {
                        internalid: self.id,
                        recordtype: self.recordtype,
                    },
                }).done(function (data) {
                    self.rendered = true;
                    self.render();
                })
            } else {
                console.log('Not Approved');
            }
        });
    } catch (ex) {
        console.log('approve order error ', ex);
    }
}

In suitescript file call suitelet and take back the response.

orderApprove: function (data) {
    var url = nlapiResolveURL("SUITELET", "customscript1519", "customdeploy1", true);
    var response = nlapiRequestURL(url, data, null, "POST");
    console.error('response', JSON.stringify(response));
    var responseCode = parseInt(response.getCode(), 10);
    if (responseCode === 200 || responseCode === 302 || responseCode === 201 || responseCode === 40) {
        var responseBody = response.getBody();
        var unescapedResponse = JSON.parse(responseBody.replace(/\\"/g, '"'));
        return {
            successMessage: "true",
            reason: unescapedResponse.reason,
            response: JSON.stringify(responseBody)
        };
    } else {
        return {
            successMessage: "false",
            reason: JSON.stringify(response.getBody()),
            response: JSON.stringify(responseBody)
        };
    }
}
post: function post() {
      try {
        console.error("inside post order approval detail entry", 1);
        var dat1 = this.data;
        this.sendContent(OrderApprovalDetail.orderApprove(this.data), { 'status': 201 });
      } catch (e) {
        console.error('errorOrderApproval ServiceController post', e);
      }
    },

Leave a comment

Your email address will not be published. Required fields are marked *