Steps for updating the standard POST method in extension for passing the request and getting the response.

We can pass the request and fetch response from the extension through this way. This the standard method. Here we passing the request for suitelet response, so we use suitelet Id in Suite Script.

this.Model = new Model()
								this.Model.save(cartObject, {
type: 'POST'
})
.done(function (data) {
})

Service controller section

define("JJ.Custom.Shipping.ServiceController", ["ServiceController", 'JJ.Custom.Shipping'], function(
  ServiceController, shippingCostModel
) {
  "use strict";
  return ServiceController.extend({
    name: "JJ.Custom.Shipping.ServiceController",
    post: function post() {
      //this function call the JJ.Custom.Shipping suitescript file
      try {
        return shippingCostModel.getShippingCostCustmization(this.data);
      } catch (error) {
        console.error("Error @ Shipping Service Controller", error);
      }
    }
  });
});

Suite Script section

define('JJ.Custom.Shipping'
,	[
		'SC.Model'
	]
,	function (
		SCModel
	)
{
	'use strict';
	return SCModel.extend({
		// This function is used to get a shipping cost response from the suitelet.
		getShippingCostCustmization: function (data) {
			try {
				var url = nlapiResolveURL("SUITELET", 'customscript_jj_sl_shiprate_calc_tfll183', 'customdeploy_jj_sl_shiprate_calc_tfll183', true);
					var response = nlapiRequestURL(url, JSON.stringify(data), null, null, 'POST');
					if (response) {
						return JSON.stringify(response);
					} else {
						return false;
					}
			} catch (error) {
				console.error("Error @ getShippingCostCustmization", error);
			}
		}
	});
});

Leave a comment

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