Jira Code: TM -96
Invoice API is functionality to export the invoice details to the server. The record details are posted to an external server using a suitelet.
In order to export the API the details a button is created in invoice and credit memo record. On button click a suitelet which calls the API is triggered using a client script.
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
/**
* Script Description
* This suitelet to .
*/
/*******************************************************************************
*
*
*
*
* NetSuite Name :
* Script ID :
*
* *****************************************************************************
*
*
* $Author: Jobin & Jismi IT Services LLP $
*
* DESCRIPTION
*
*
* Date Created :
*
* REVISION HISTORY Update:
*
*
*
******************************************************************************/
define(['N/file', 'N/search', 'N/runtime', 'N/record', 'N/https', 'N/encode', 'N/ui/serverWidget', 'N/email'],
function(file, search, runtime, record, https, encode, serverWidget, email) {
var main = {
onRequest: function(context) {
var recid = context.request.parameters.recid;
var rectype = context.request.parameters.rectype;
log.debug("rectype", rectype);
if (rectype == "creditmemo") {
var creditRecord = record.load({
type: record.Type.CREDIT_MEMO,
id: recid,
isDynamic: true
});
var recid = creditRecord.getValue({ fieldId: "createdfrom" });
log.debug("created", recid);
}
if (recid == "") {
var recid = context.request.parameters.recid;
var records = creditRecord;
var isCredit = true;
} else {
var records = record.load({
type: record.Type.INVOICE,
id: recid,
isDynamic: true
});
}
var array = [];
var contentObj = {};
contentObj.CustAccount = records.getText({
fieldId: 'entityid'
});
contentObj.CustHead = "ZZMISC"
contentObj.DepartHead = "674800";
if (isCredit != true) {
contentObj.ShippingDateRequested = records.getValue({
fieldId: 'shipdate'
});
contentObj.ShippingDateRequested = contentObj.ShippingDateRequested.toISOString().split("T")[0];
} else {
contentObj.ShippingDateRequested = contentObj.ShippingDateRequested = records.getValue({
fieldId: 'trandate'
});
contentObj.ShippingDateRequested = contentObj.ShippingDateRequested.toISOString().split("T")[0];
}
contentObj.RecordType = rectype;
if (rectype == "creditmemo") {
contentObj.NetsuiteInvoice = creditRecord.getValue({
fieldId: 'tranid'
});
} else {
contentObj.NetsuiteInvoice = records.getValue({
fieldId: 'tranid'
});
}
contentObj.ProposalNum = records.getText({
fieldId: 'createdfrom'
}).split(" ")[1];
// contentObj.NetsuiteInvoice = "#" + contentObj.NetsuiteInvoice
contentObj.CustomerReference = records.getText({
fieldId: 'otherrefnum'
});
contentObj.Pool = "MKTG";
contentObj.Region = records.getValue({
fieldId: 'custbodyid_region'
});
contentObj.AdvertiserAccountID = records.getText({
fieldId: 'custbody1'
});
/*Fetch Contact Details*/
var contactget = records.getValue({
fieldId: 'entity'
});
log.debug("contactget", contactget);
var customer = record.load({
type: record.Type.CUSTOMER,
id: contactget
});
contentObj.Contactperson = customer.getText({
fieldId: 'contact'
});
contentObj.CustAccount = customer.getValue({
fieldId: 'custentity_jj_tm88_client_code'
});
log.debug("gaaga", records.getText({
fieldId: 'billcity'
}))
contentObj.City = records.getValue({
fieldId: 'billcity'
});
contentObj.CountryRegionID = records.getValue({
fieldId: 'billcountry'
});
contentObj.State = records.getValue({
fieldId: 'billstate'
});
contentObj.Street = records.getValue({
fieldId: 'billaddr1'
});
contentObj.ZipCode = records.getValue({
fieldId: 'billzip'
});
if (isCredit == true) {
var invoiceSearchObj = main.searchTransaction("creditmemo", "CustCred", recid);
} else {
var invoiceSearchObj = main.searchTransaction("invoice", "CustInvc", recid);
}
var searchResultCount = invoiceSearchObj.runPaged().count;
log.debug("invoiceSearchObj result count", searchResultCount);
invoiceSearchObj.run().each(function(result) {
contentObj.City = result.getValue({ name: "billcity", label: "Billing City" });
contentObj.State = result.getValue({ name: "billstate", label: "Billing State/Province" });
contentObj.Street = result.getValue({ name: "billaddress1", label: "Billing Address 1" });
contentObj.ZipCode = result.getValue({ name: "billzip", label: "Billing City" });
contentObj.CountryRegionID = result.getValue({ name: "billcountry", label: "Billing Country" });
if (contentObj.CountryRegionID == "US")
contentObj.CountryRegionID = "USA"
contentObj.Contactperson = result.getValue({ name: "billattention", label: "Billing Attention" });
contentObj.ShipCity = result.getValue({ name: "shipcity", label: "Shipping City" });
contentObj.ShipState = result.getValue({ name: "shipstate", label: "Shipping State/Province" });
contentObj.ShipStreet = result.getValue({ name: "shipaddress1", label: "Shipping Address 1" });
contentObj.ShipZipCode = result.getValue({ name: "shipzip", label: "ship Zip" });
contentObj.ShipCountryRegionID = result.getValue({ name: "shipcountry", label: "Shipping Country" });
if (contentObj.ShipCountryRegionID == "US")
contentObj.ShipCountryRegionID = "USA"
contentObj.ShipContactperson = result.getValue({ name: "shippingattention", label: "Shipping Attention" });
contentObj.UserName = result.getText({ name: "createdby", label: "Created By" });
contentObj.SalesRep = result.getText({ name: "salesrep", label: "salesrep" });
if (contentObj.Contactperson == "") {
contentObj.Contactperson = result.getValue({
name: "entityid",
join: "contactPrimary",
label: "Name"
});
}
return true;
});
if (rectype == "creditmemo") {
var internalarray = [];
var memo = creditRecord.getValue({
fieldId: 'memo'
});
log.debug("memo", memo);
if (memo == null || memo == "") {
} else {
var memoitem = {};
memoitem.ItemId = "TEXT"
memoitem.SalesPrice = "0"
memoitem.SalesQty = "1"
memoitem.SalesUnit = "0"
memoitem.TotalAmt = "0"
memoitem.Name = memo
var car = {
"Value": [{
"Name": "Client",
"Value": contentObj.CustAccount
}, {
"Name": "Country",
"Value": "USA"
}, {
"Name": "Customer",
"Value": "ZZMISC"
}, {
"Name": "Department",
"Value": "674300"
}]
}
memoitem.DefaultDimension = car;
internalarray.push(memoitem);
}
var numLines = creditRecord.getLineCount({
sublistId: 'item'
});
for (var k = 0; k < numLines; k++) {
var itemObj = {};
var ItemId = creditRecord.getSublistValue({
sublistId: 'item',
fieldId: "item",
line: k
});
var itemtype = creditRecord.getSublistValue({
sublistId: 'item',
fieldId: "itemtype",
line: k
});
itemObj.ItemId = main.returnItemId(ItemId, recid, "CustCred", "creditmemo")
itemObj.SalesPrice = creditRecord.getSublistValue({
sublistId: 'item',
fieldId: "rate",
line: k
});
itemObj.SalesQty = creditRecord.getSublistValue({
sublistId: 'item',
fieldId: "quantity",
line: k
});
if (rectype == "creditmemo") {
itemObj.SalesQty = "-" + itemObj.SalesQty
}
itemObj.SalesUnit = " ";
itemObj.Name = creditRecord.getSublistValue({
sublistId: 'item',
fieldId: "description",
line: k
});
itemObj.TotalAmt = creditRecord.getSublistValue({
sublistId: 'item',
fieldId: "amount",
line: k
});
itemObj.DefaultDimension = {
"Value": [{
"Name": "Client",
"Value": contentObj.CustAccount
}, {
"Name": "Country",
"Value": "USA"
}, {
"Name": "Customer",
"Value": "ZZMISC"
}, {
"Name": "Department",
"Value": "674300"
}]
}
internalarray.push(itemObj);
}
contentObj.SalesLine = internalarray;
array.push(contentObj);
log.debug("array", array)
} else {
var internalarray = [];
var memo = records.getValue({
fieldId: 'memo'
});
log.debug("memo", memo);
if (memo == null || memo == "") {
} else {
var memoitem = {};
memoitem.ItemId = "TEXT"
memoitem.SalesPrice = "0"
memoitem.SalesQty = "1"
memoitem.SalesUnit = "0"
memoitem.TotalAmt = "0"
memoitem.Name = memo
var car = {
"Value": [{
"Name": "Client",
"Value": contentObj.CustAccount
}, {
"Name": "Country",
"Value": "USA"
}, {
"Name": "Customer",
"Value": "ZZMISC"
}, {
"Name": "Department",
"Value": "674300"
}]
}
memoitem.DefaultDimension = car;
internalarray.push(memoitem);
}
var numLines = records.getLineCount({
sublistId: 'item'
});
for (var k = 0; k < numLines; k++) {
var itemObj = {};
var ItemId = records.getSublistValue({
sublistId: 'item',
fieldId: "item",
line: k
});
var itemtype = records.getSublistValue({
sublistId: 'item',
fieldId: "itemtype",
line: k
});
itemObj.ItemId = main.returnItemId(ItemId, recid, "CustInvc", "invoice");
itemObj.SalesPrice = records.getSublistValue({
sublistId: 'item',
fieldId: "rate",
line: k
});
itemObj.SalesQty = records.getSublistValue({
sublistId: 'item',
fieldId: "quantity",
line: k
});
itemObj.SalesUnit = " ";
itemObj.Name = records.getSublistValue({
sublistId: 'item',
fieldId: "description",
line: k
});
itemObj.TotalAmt = records.getSublistValue({
sublistId: 'item',
fieldId: "amount",
line: k
});
itemObj.DefaultDimension = {
"Value": [{
"Name": "Client",
"Value": contentObj.CustAccount
}, {
"Name": "Country",
"Value": "USA"
}, {
"Name": "Customer",
"Value": "ZZMISC"
}, {
"Name": "Department",
"Value": "674300"
}]
}
internalarray.push(itemObj);
}
contentObj.SalesLine = internalarray;
array.push(contentObj);
log.debug("array", array);
}
var header = { "Content-Type": "application/json" };
var response = https.post({
url: 'https://cms.take5media.net/T5MAPI/GenerateInvoiceToAX/',
body: JSON.stringify(array),
headers: header
});
log.debug("response", response.body);
// var car = { "msg": "Success" };
context.response.write(response.body);
// context.response.write(JSON.stringify(car));
},
returnItemId: function(itemId, invoice, type, rectype) {
var invoiceSearchObj = search.create({
type: rectype,
filters: [
["type", "anyof", type],
"AND",
["account", "noneof", "329"],
"AND",
["item", "anyof", itemId],
"AND",
["internalid", "anyof", invoice]
],
columns: [
search.createColumn({ name: "billstate", label: "Billing State/Province" }),
search.createColumn({ name: "billaddress1", label: "Billing Address 1" }),
search.createColumn({ name: "billcity", label: "Billing City" }),
search.createColumn({ name: "billzip", label: "Billing Zip" }),
search.createColumn({ name: "billcountry", label: "Billing Country" }),
search.createColumn({ name: "billaddressee", label: "Billing Addressee" }),
search.createColumn({
name: "formulatext",
formula: "SUBSTR({account},0,5)",
label: "Formula (Text)"
}),
search.createColumn({ name: "account", label: "Account" })
]
});
var searchResultCount = invoiceSearchObj.runPaged().count;
var accountID;
invoiceSearchObj.run().each(function(result) {
accountID = result.getValue({
name: "formulatext",
formula: "SUBSTR({account},0,5)",
label: "Formula (Text)"
});
return true;
});
return accountID;
},
searchTransaction: function(type, recordName, recid) {
var searchObj = search.create({
type: type,
filters: [
["type", "anyof", recordName],
"AND",
["internalid", "anyof", recid],
"AND",
["mainline", "is", "T"]
],
columns: [
search.createColumn({ name: "billstate", label: "Billing State/Province" }),
search.createColumn({ name: "billaddress1", label: "Billing Address 1" }),
search.createColumn({ name: "billcity", label: "Billing City" }),
search.createColumn({ name: "billzip", label: "Billing Zip" }),
search.createColumn({ name: "billcountry", label: "Billing Country" }),
search.createColumn({ name: "billaddressee", label: "Billing Addressee" }),
search.createColumn({ name: "billattention", label: "Billing Attention" }),
search.createColumn({
name: "entityid",
join: "contactPrimary",
label: "Name"
}),
search.createColumn({ name: "createdby", label: "Created By" }),
search.createColumn({ name: "salesrep", label: "salesrep" }),
search.createColumn({ name: "shipstate", label: "Shipping State/Province" }),
search.createColumn({ name: "shipaddress1", label: "Shipping Address 1" }),
search.createColumn({ name: "shipzip", label: "ship Zip" }),
search.createColumn({ name: "shipcity", label: "Shipping City" }),
search.createColumn({ name: "shipcountry", label: "Shipping Country" }),
search.createColumn({ name: "shipaddressee", label: "Shipping Addressee" }),
search.createColumn({ name: "shippingattention", label: "Shipping Attention" })
]
});
return searchObj;
}
}
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;
});
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
/*******************************************************************************
* AHD 3 Split Item Line
* **************************************************************************
*
* Date: 24-07-2018
*
* Author: Jobin & Jismi IT Services LLP
*
*****************************************************************************
**/
define(['N/file', 'N/url', 'N/search', 'N/runtime', 'N/record', 'N/https', 'N/ui/serverWidget', 'N/email'],
function(file, url, search, runtime, record, https, serverWidget, email) {
var main = {
beforeLoad: function(scriptContext) {
if (scriptContext.type != "create") {
scriptContext.form.addButton({
id: 'custpage_testbutton',
label: 'AX Export',
functionName: 'testingjj'
});
scriptContext.form.clientScriptFileId = '1067';
}
},
afterSubmit: function(scriptContext) {
var recid = scriptContext.currentRecord.id;
var rectype = scriptContext.currentRecord.type;
log.debug("rectype", rectype);
if (rectype == "creditmemo") {
var creditRecord = record.load({
type: record.Type.CREDIT_MEMO,
id: recid,
isDynamic: true
});
var recid = creditRecord.getValue({ fieldId: "createdfrom" });
log.debug("created", recid);
}
if (recid == "") {
var recid = context.request.parameters.recid;
var records = creditRecord;
var isCredit = true;
} else {
var records = record.load({
type: record.Type.INVOICE,
id: recid,
isDynamic: true
});
}
var array = [];
var contentObj = {};
contentObj.CustAccount = records.getText({
fieldId: 'entityid'
});
contentObj.CustHead = "ZZMISC"
contentObj.DepartHead = "674800";
if (isCredit != true) {
contentObj.ShippingDateRequested = records.getValue({
fieldId: 'shipdate'
});
contentObj.ShippingDateRequested = contentObj.ShippingDateRequested.toISOString().split("T")[0];
} else {
contentObj.ShippingDateRequested = contentObj.ShippingDateRequested = records.getValue({
fieldId: 'trandate'
});
contentObj.ShippingDateRequested = contentObj.ShippingDateRequested.toISOString().split("T")[0];
}
if (rectype == "creditmemo") {
contentObj.NetsuiteInvoice = creditRecord.getValue({
fieldId: 'tranid'
});
} else {
contentObj.NetsuiteInvoice = records.getValue({
fieldId: 'tranid'
});
}
contentObj.ProposalNum = records.getText({
fieldId: 'createdfrom'
}).split(" ")[1];
// contentObj.NetsuiteInvoice = "#" + contentObj.NetsuiteInvoice
contentObj.CustomerReference = records.getText({
fieldId: 'otherrefnum'
});
contentObj.Pool = "MKTG";
contentObj.Region = records.getValue({
fieldId: 'custbodyid_region'
});
contentObj.AdvertiserAccountID = records.getText({
fieldId: 'custbody1'
});
/*Fetch Contact Details*/
var contactget = records.getValue({
fieldId: 'entity'
});
log.debug("contactget", contactget);
var customer = record.load({
type: record.Type.CUSTOMER,
id: contactget
});
contentObj.Contactperson = customer.getText({
fieldId: 'contact'
});
contentObj.CustAccount = customer.getValue({
fieldId: 'custentity_jj_tm88_client_code'
});
log.debug("gaaga", records.getText({
fieldId: 'billcity'
}))
contentObj.City = records.getValue({
fieldId: 'billcity'
});
contentObj.CountryRegionID = records.getValue({
fieldId: 'billcountry'
});
contentObj.State = records.getValue({
fieldId: 'billstate'
});
contentObj.Street = records.getValue({
fieldId: 'billaddr1'
});
contentObj.ZipCode = records.getValue({
fieldId: 'billzip'
});
if (isCredit == true) {
var invoiceSearchObj = main.searchTransaction("creditmemo", "CustCred", recid);
} else {
var invoiceSearchObj = main.searchTransaction("invoice", "CustInvc", recid);
}
var searchResultCount = invoiceSearchObj.runPaged().count;
log.debug("invoiceSearchObj result count", searchResultCount);
invoiceSearchObj.run().each(function(result) {
contentObj.City = result.getValue({ name: "billcity", label: "Billing City" });
contentObj.State = result.getValue({ name: "billstate", label: "Billing State/Province" });
contentObj.Street = result.getValue({ name: "billaddress1", label: "Billing Address 1" });
contentObj.ZipCode = result.getValue({ name: "billzip", label: "Billing City" });
contentObj.CountryRegionID = result.getValue({ name: "billcountry", label: "Billing Country" });
if (contentObj.CountryRegionID == "US")
contentObj.CountryRegionID = "USA"
contentObj.Contactperson = result.getValue({ name: "billattention", label: "Billing Attention" });
contentObj.ShipCity = result.getValue({ name: "shipcity", label: "Shipping City" });
contentObj.ShipState = result.getValue({ name: "shipstate", label: "Shipping State/Province" });
contentObj.ShipStreet = result.getValue({ name: "shipaddress1", label: "Shipping Address 1" });
contentObj.ShipZipCode = result.getValue({ name: "shipzip", label: "ship Zip" });
contentObj.ShipCountryRegionID = result.getValue({ name: "shipcountry", label: "Shipping Country" });
if (contentObj.ShipCountryRegionID == "US")
contentObj.ShipCountryRegionID = "USA"
contentObj.ShipContactperson = result.getValue({ name: "shippingattention", label: "Shipping Attention" });
contentObj.UserName = result.getText({ name: "createdby", label: "Created By" });
contentObj.SalesRep = result.getText({ name: "salesrep", label: "salesrep" });
if (contentObj.Contactperson == "") {
contentObj.Contactperson = result.getValue({
name: "entityid",
join: "contactPrimary",
label: "Name"
});
}
return true;
});
if (rectype == "creditmemo") {
var internalarray = [];
var memo = creditRecord.getValue({
fieldId: 'memo'
});
log.debug("memo", memo);
if (memo == null || memo == "") {
} else {
var memoitem = {};
memoitem.ItemId = "TEXT"
memoitem.SalesPrice = "0"
memoitem.SalesQty = "1"
memoitem.SalesUnit = "0"
memoitem.TotalAmt = "0"
memoitem.Name = memo
var car = {
"Value": [{
"Name": "Client",
"Value": contentObj.CustAccount
}, {
"Name": "Country",
"Value": "USA"
}, {
"Name": "Customer",
"Value": "ZZMISC"
}, {
"Name": "Department",
"Value": "674300"
}]
}
memoitem.DefaultDimension = car;
internalarray.push(memoitem);
}
var numLines = creditRecord.getLineCount({
sublistId: 'item'
});
for (var k = 0; k < numLines; k++) {
var itemObj = {};
var ItemId = creditRecord.getSublistValue({
sublistId: 'item',
fieldId: "item",
line: k
});
var itemtype = creditRecord.getSublistValue({
sublistId: 'item',
fieldId: "itemtype",
line: k
});
itemObj.ItemId = main.returnItemId(ItemId, recid, "CustCred", "creditmemo");
itemObj.SalesPrice = creditRecord.getSublistValue({
sublistId: 'item',
fieldId: "rate",
line: k
});
itemObj.SalesQty = creditRecord.getSublistValue({
sublistId: 'item',
fieldId: "quantity",
line: k
});
if (rectype == "creditmemo") {
itemObj.SalesQty = "-" + itemObj.SalesQty
}
itemObj.SalesUnit = " ";
itemObj.Name = creditRecord.getSublistValue({
sublistId: 'item',
fieldId: "description",
line: k
});
itemObj.TotalAmt = creditRecord.getSublistValue({
sublistId: 'item',
fieldId: "amount",
line: k
});
itemObj.DefaultDimension = {
"Value": [{
"Name": "Client",
"Value": contentObj.CustAccount
}, {
"Name": "Country",
"Value": "USA"
}, {
"Name": "Customer",
"Value": "ZZMISC"
}, {
"Name": "Department",
"Value": "674300"
}]
}
internalarray.push(itemObj);
}
contentObj.SalesLine = internalarray;
array.push(contentObj);
log.debug("array", array)
} else {
var internalarray = [];
var memo = records.getValue({
fieldId: 'memo'
});
log.debug("memo", memo);
if (memo == null || memo == "") {
} else {
var memoitem = {};
memoitem.ItemId = "TEXT"
memoitem.SalesPrice = "0"
memoitem.SalesQty = "1"
memoitem.SalesUnit = "0"
memoitem.TotalAmt = "0"
memoitem.Name = memo
var car = {
"Value": [{
"Name": "Client",
"Value": contentObj.CustAccount
}, {
"Name": "Country",
"Value": "USA"
}, {
"Name": "Customer",
"Value": "ZZMISC"
}, {
"Name": "Department",
"Value": "674300"
}]
}
memoitem.DefaultDimension = car;
internalarray.push(memoitem);
}
var numLines = records.getLineCount({
sublistId: 'item'
});
for (var k = 0; k < numLines; k++) {
var itemObj = {};
var ItemId = records.getSublistValue({
sublistId: 'item',
fieldId: "item",
line: k
});
var itemtype = records.getSublistValue({
sublistId: 'item',
fieldId: "itemtype",
line: k
});
itemObj.ItemId = main.returnItemId(ItemId, recid, "CustInvc", "invoice");
itemObj.SalesPrice = records.getSublistValue({
sublistId: 'item',
fieldId: "rate",
line: k
});
itemObj.SalesQty = records.getSublistValue({
sublistId: 'item',
fieldId: "quantity",
line: k
});
itemObj.SalesUnit = " ";
itemObj.Name = records.getSublistValue({
sublistId: 'item',
fieldId: "description",
line: k
});
itemObj.TotalAmt = records.getSublistValue({
sublistId: 'item',
fieldId: "amount",
line: k
});
itemObj.DefaultDimension = {
"Value": [{
"Name": "Client",
"Value": contentObj.CustAccount
}, {
"Name": "Country",
"Value": "USA"
}, {
"Name": "Customer",
"Value": "ZZMISC"
}, {
"Name": "Department",
"Value": "674300"
}]
}
internalarray.push(itemObj);
}
contentObj.SalesLine = internalarray;
array.push(contentObj);
log.debug("array", array);
}
}
};
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;
});
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
/**
* Script Description
* This ClientScript for the filter action.
*/
/*******************************************************************************
* NetSuite Name :
*
* Dependent to :
*
* *****************************************************************************
*
*
* $Author: Jobin & Jismi IT Services LLP $
*
* DESCRIPTION
* FullFillment Item Report.
*
* Date Created :19/07/2018
*
* REVISION HISTORY Update:
* 7u654321`54321`
*
*
******************************************************************************/
define(['N/record', 'N/search', 'N/currentRecord', 'N/https', 'N/url', 'N/ui/message'],
function(record, search, currentRecord, https, url, message) {
var main = {
pageInit: function(context) {},
proposalRedirect: function() {
var recordinitial = currentRecord.get();
console.log("es");
window.location.href = "https://4268438.app.netsuite.com/app/accounting/transactions/salesord.nl?entity=" + recordinitial.id + "&whence="
},
testingjj: function(context) {
var recordinitial = currentRecord.get();
// var response = https.post({
// url: 'https://system.na1.netsuite.com/app/site/hosting/scriptlet.nl?script=99&deploy=1&recid=' + recordinitial.id + '&rectype=' + recordinitial.type,
// body: recordinitial.id
// });
jQuery('#custpage_testbutton').prop('disabled', true);
jQuery('#custpage_testbutton').hide();
var output = url.resolveScript({
scriptId: 'customscript_jj_se_invoice_api',
deploymentId: 'customdeploy1',
returnExternalUrl: true
});
https.post.promise({
url: output + '&recid=' + recordinitial.id + '&rectype=' + recordinitial.type,
body: recordinitial.id
})
.then(function(response) {
console.log(response);
var response = JSON.parse(response.body);
jQuery('#custpage_testbutton').prop('disabled', false);
jQuery('#custpage_testbutton').show();
if (response.msg == "Success") {
var myMsg = message.create({
title: "Exported",
message: "Successfully",
type: message.Type.CONFIRMATION
});
myMsg.show({
duration: 5000
});
var currentdate = new Date();
var dd = currentdate.getDate();
var mm = currentdate.getMonth() + 1;
var yyyy = currentdate.getFullYear();
var datefetch = mm + '/' + dd + '/' + yyyy;
//edited by jj
/*if (recordinitial.type == 'invoice') {
//main.loadRecord("invoice", recordinitial.id, datefetch);
} else if (recordinitial.type == "creditmemo") {
//main.loadRecord("creditmemo", recordinitial.id, datefetch);
}*/
https.post.promise({
url: output + 'recid=' + recordinitial.id + '&rectype=' + recordinitial.type + '&datefetch=' + datefetch,
body: recordinitial.id
}).then(function(response) {
window.location.reload();
});
} else {
var myMsg = message.create({
title: "Exported",
message: "Failed",
type: message.Type.ERROR
});
myMsg.show({
duration: 5000
});
}
}).catch(function onRejected(reason) {
console.log(reason);
});
// console.log(response);
// var response = JSON.parse(response.body);
// if (response.msg == "Success") {
// var myMsg = message.create({
// title: "Exported",
// message: "Successfully",
// type: message.Type.CONFIRMATION
// });
// myMsg.show({
// duration: 5000
// });
// //window.location.reload();
// } else {
// var myMsg = message.create({
// title: "Exported",
// message: "Failed",
// type: message.Type.ERROR
// });
// myMsg.show({
// duration: 5000
// });
// }
}
/*,
loadRecord: function(recordLoad, id, datefetch) {
console.log('datefetch', datefetch);
var loadRecordPromise = record.load.promise({
type: recordLoad,
id: id
});
loadRecordPromise.then(function(objRecord) {
objRecord.setText({
fieldId: 'custbodylast_ax_export_date',
text: datefetch
});
var recordId = objRecord.save();
window.location.reload();
}, function(e) {
console.log(e);
});
}*/
};
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) {
console.error(e);
}
}
};
return main
});