Jira Code: EN-55
When an order is cancelled in NetSuite that respective order has to be deleted in Bronto.
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
/*******************************************************************************
* EN-55 UE Script to Delete Order in Bront
* *************************************************************************
*
* Date: 01-08-2018
*
* Updated date :
*
* Author: Jobin & Jismi IT Services LLP
*
*****************************************************************************
**/
define(['N/file', 'N/url', 'N/search', 'N/runtime', 'N/record', 'N/https', 'N/ui/serverWidget', 'N/email', 'N/task', 'N/format'],
function (file, url, search, runtime, record, https, serverWidget, email, task, format) {
var main = {
beforeLoad: function (scriptContext) {
},
beforeSubmit: function (scriptContext) {
if (scriptContext.type==scriptContext.UserEventType.CANCEL) {
var bodyObj = {
client_secret: 'bd2bde692e7ca6e6f5c0d2e5e7f40a6bbc56deed',
client_id: '1100b2ad08daec7ab916d6a6e23d3e86f1898a3c',
grant_type: 'client_credentials'
};
var headerObj = {
"Content-Type": 'application/x-www-form-urlencoded',
"Accept": 'application/json'
};
var response = https.post({
url: 'https://auth.bronto.com/oauth2/token',
body: bodyObj,
headers: headerObj
});
var accessToken=response.body
log.debug("accessToken",JSON.parse(accessToken).access_token)
var deliveryObject = scriptContext.newRecord;
var bronto_id = deliveryObject.getValue({
fieldId: 'custbody_bronto_id'
});
var headerObj_1 = {
"Authorization": 'Bearer '+JSON.parse(accessToken).access_token,
"Accept": 'application/json',
"Content-Type":'application/json'
};
var response_1 = https.delete({
url: 'https://rest.bronto.com/orders/'+bronto_id,
headers: headerObj_1
});
log.debug("response_1",response_1)
}
},
afterSubmit: function (scriptContext) {
},
};
for (var key in main) {
if (typeof main[key] === 'function') {
main[key] = trycatch(main[key], key);
}
}
function trycatch(myfunction, key) {
return function () {
try {
return myfunction.apply(this, arguments);
} catch (e) {
log.debug("e in " + key, e);
}
}
};
return main;
});