The approver can possibly update the item from the sales order. Once approved increment/decrement needs to forward the action to Suitelet and update the item from the sales order. once the item is update success need to rerender the page with updated items. The suite script change updated the quantity
updateQuantity: function updateQuantity(e) {
try {
var self = this;
var profile = ProfileModel.ProfileModel ? ProfileModel.ProfileModel.getInstance() : ProfileModel.getInstance();
var customFields = profile.attributes.customfields;
var checkApprover = _.findWhere(customFields, {
name: "custentity_jj_approver"
})
var $forms = $(e.target).closest('[data-type="order-item"]');
var $alert_placeholder_out = $forms.find('[data-type=alert-placeholder-quantity]');
var messageOut;
if (self.model.attributes.options.custbody_jj_approval_status === '1' && checkApprover.value) {
// Get the QUANTITY value
var valueQuantity = parseInt(e.target.value);
// Get the transactionID
var transid = self.id;
// Get the SKU value
var sku = e.target.getAttribute('sku');
// Use the SKU value as needed
var object = {
Action: 'Update',
SO_Id: transid,
quantity: valueQuantity,
itemid: sku
}
this.ApprovalModel.save(object, {
type: 'POST'
}).fail(function (e) {
var error = e.responseJSON;
self.showError(error.errorMessage);
}).done(function (data) {
var $form = $(e.target).closest('[data-type="order-item"]');
var $alert_placeholder = $form.find('[data-type=alert-placeholder-quantity]');
var message;
var success = data.successMessage;
var reason = data.reason;
// Check the value of the success
if (success == "false") {
message = Utils.translate('Sorry! The Quantity is not updated<br/>' + reason);
var alert = new GlobalViewsMessageView({
message: message,
type: 'warning',
closable: true
});
alert.show($alert_placeholder, 6000);
} else {
message = Utils.translate('The Quantity updated successfully');
var alert = new GlobalViewsMessageView({
message: message,
type: 'success',
closable: true
});
alert.show($alert_placeholder, 6000);
//to render view
self.ApprovalModel.fetch({
data: {
internalid: self.id,
recordtype: self.recordtype,
},
}).done(function (data) {
self.render();
})
}
});
} else {
messageOut = Utils.translate('Sorry! There is no Permission to update Quantity<br/>');
var alert = new GlobalViewsMessageView({
message: messageOut,
type: 'warning',
closable: true
});
alert.show($alert_placeholder_out, 6000);
}
} catch (ex) {
console.log('approve order error ', ex);
}
},
orderApprove: function (data) {
var url = nlapiResolveURL("SUITELET", "customscript_jj_sl_actionapprreq_ccus123", "customdeploy_jj_sl_actionapprreq_ccus123", 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)
};
}
},