/**
* @NApiVersion 2.x
* @NScriptType Restlet
* @NModuleScope Public
* @description assert project sync other system SO to netsuite
* @author WZ
* @copyright netsuite Oracle
* @version 1.0
*/
define(['N/record', 'N/search', 'N/error', './configInfo.js'],
function (record, search, error, configInfo) {
var configObj = configInfo.configInfo();
/**
* Function called upon sending a GET request to the RESTlet.
*
* @param {Object} requestParams - Parameters from HTTP request URL; parameters will be passed into function as an Object (for all supported content types)
* @returns {string | Object} HTTP response body; return string when request Content-Type is 'text/plain'; return Object when request Content-Type is 'application/json'
* @since 2015.1
*/
function doGet(requestParams) {
}
/**
* Function called upon sending a PUT request to the RESTlet.
*
* @param {string | Object} requestBody - The HTTP request body; request body will be passed into function as a string when request Content-Type is 'text/plain'
* or parsed into an Object when request Content-Type is 'application/json' (in which case the body must be a valid JSON)
* @returns {string | Object} HTTP response body; return string when request Content-Type is 'text/plain'; return Object when request Content-Type is 'application/json'
* @since 2015.2
*/
function doPut(requestBody) {
}
/**
* Function called upon sending a POST request to the RESTlet.
*
* @param {string | Object} requestBody - The HTTP request body; request body will be passed into function as a string when request Content-Type is 'text/plain'
* or parsed into an Object when request Content-Type is 'application/json' (in which case the body must be a valid JSON)
* @returns {string | Object} HTTP response body; return string when request Content-Type is 'text/plain'; return Object when request Content-Type is 'application/json'
* @since 2015.2
*/
function doPost(requestBody) {
var realResults = forSingleSalesOrder(requestBody);
return realResults
}
function forSingleSalesOrder(params) {
var resultObkArr = {
'create': [], 'update': [], 'error': [] };
log.debug('modual config', configObj)
try {
var isDuplicate = searchDupSo(params);
// var singelRes = {}
if (isDuplicate) {
var update_so_id = updateSoBySoid(params, isDuplicate);
if (update_so_id) {
resultObkArr.update.push(params.body[configObj.uniqueFieldId.extraInfo])
}
// singelRes[success] = params.tranId;
} else {
var new_id = CreateSalesOrder(params)
log.debug('new_id', new_id)
if (-1 == new_id) {
} else {
resultObkArr.create.push(params.body[configObj.uniqueFieldId.extraInfo])
}
}
return resultObkArr;
} catch (error) {
log.debug('error', error)
var error_obj = {
};
error_obj.name = error.name;
error_obj.message = error.message;
error_obj.tranId = params.tranId;
resultObkArr.error.push(error_obj)
return resultObkArr;
}
}
/**
*
* @param {*} requestBody
* @description search so by unique identifier
* @returns internalId_update :false or internal id
*/
function searchDupSo(requestBody) {
var salesorderSearchObj = search.create({
type: "salesorder",
filters:
[
[configObj.uniqueFieldId.extraInfo, "is", requestBody.body[configObj.uniqueFieldId.extraInfo]],
"AND",
["type", "anyof", "SalesOrd"],
"AND",
["mainline", "is", "T"]
],
columns:
[
search.createColumn({
name: "internalid", label: "Internal ID" })
]
});
var searchResultCount = salesorderSearchObj.runPaged().count;
log.debug("salesorderSearchObj result count", searchResultCount);
if (searchResultCount) {
var internalId_update;
salesorderSearchObj.run().each(function (result) {
// .run().each has a limit of 4,000 results
internalId_update = result.id;
log.debug('internalId_update', internalId_update)
return true;
});
return internalId_update;
} else {
return false
}
}
function CreateSalesOrder(params) {
/**
* create a dynamic salesorder record
*/
var soRecord = record.create({
type: 'salesorder',
isDynamic: true
})
for (var key in params.body) {
// No. 1 custom form
if ('customform' == key) {
/**
* if other sys wants set form should set this key
* internal id not provide
*/
if (configObj[key].name) {
} else {
soRecord.setValue({
fieldId: key,
value: params.body[key]
});
}
} else
// No.2 customer field
if ('entity' == key) {
/**
* if ns customer internal id not provide
*/
if (configObj[key].name) {
// search ns customer id by other system customer id
var customerSearchObj = search.create({
type: "customer",
filters:
[
[configObj[key].extraInfo, "is", params.body[key]],
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交