英文:
Scheduled Script Error: SuiteScript 2.x entry point scripts must implement one script type function
问题
以下是您提供的脚本的翻译部分:
/**
* 此脚本在销售订单获得批准时查找已售出的原件,并在订单获得批准时标记父项、子项和套件为已售出,以及在履行时停用父项、子项和套件。
*
* @NApiVersion 2.x
* @NScriptType ScheduledScript
* @NModuleScope SameAccount
*/
define(['N/search', 'N/record', 'N/log'], function (search, record, log) {
function createSoldOriginalSearch() {
return search.create({
type: "salesorder",
filters: [
["type", "anyof", "SalesOrd"],
"AND",
["item.custitemitemoriginal", "is", "T"],
"AND",
["item.isinactive", "is", "F"],
"AND",
["datecreated", "within", "lastmonth"]
],
columns: [
"statusref",
"shiprecvstatusline",
search.createColumn({
name: "type",
join: "item"
}),
search.createColumn({
name: "formulatext",
formula: "CASE WHEN {item.type}='Kit/Package' THEN SUBSTR({item.memberitem}, 0, 6) ELSE SUBSTR({item}, 0, 6) END"
}),
"internalid"
]
});
}
function getAllResults(searchObj) {
var start = 0;
var allResults = [];
var results = [];
var resultSet = searchObj.run();
results = resultSet.getRange({
start: start,
end: start + 1000
});
allResults = allResults.concat(results);
while (results.length) {
start += 1000;
results = resultSet.getRange({
start: start,
end: start + 1000
});
allResults = allResults.concat(results);
}
return allResults;
}
function getOrderInfo(results, index) {
var orderInfo = {};
orderInfo.id = results[index].id;
orderInfo.SOInternalId = results[index].getValue('internalid');
orderInfo.masterItemNum = results[index].getValue('formulatext');
orderInfo.SOStatus = results[index].getText('statusref');
orderInfo.itemFulfillStatus = results[index].getText('shiprecvstatusline');
return orderInfo;
}
function getItemIds(orderInfo) {
var searchFilter = search.createFilter({
name: 'itemid',
operator: search.Operator.CONTAINS,
values: orderInfo.masterItemNum
});
var inventorySearch = search.create({
type: search.Type.ITEM,
filters: [searchFilter],
columns: ['internalid']
});
var itemSearchResults = inventorySearch.run().getRange({
start: 0,
end: 1000 // 更改此值以检索更多或更少的结果。
});
return itemSearchResults;
}
function markAsSoldOut(orderInfo, itemId) {
var itemRecord = record.load({
type: record.Type.SERIALIZED_INVENTORY_ITEM,
id: itemId,
});
if (orderInfo.SOStatus !== 'Pending Approval' && orderInfo.SOStatus !== 'Closed' && orderInfo.SOStatus !== 'Cancelled') {
itemRecord.setValue({
fieldId: 'custitemsold_out',
value: true,
});
}
var saveSoldOut = record.save();
return saveSoldOut;
}
function inactivateItems(orderInfo, itemId) {
var itemRecord = record.load({
type: record.Type.SERIALIZED_INVENTORY_ITEM, // 假设您想要停用该项目记录
id: itemId,
});
if (orderInfo.itemFulfillStatus == 'true') {
itemRecord.setValue({
fieldId: 'isinactive',
value: true,
});
}
var saveInactivate = record.save();
return saveInactivate;
}
function execute(context) {
try {
var soldOriginalSearch = createSoldOriginalSearch();
var results = getAllResults(soldOriginalSearch);
log.debug('initial results', results);
for (var i = 0; i < results.length; i++) {
var orderInfo = getOrderInfo(results, i);
log.debug('orderinfo', orderInfo);
var itemResults = getItemIds(orderInfo);
if (itemResults && itemResults.length > 0) {
for (var j = 0; j < itemResults.length; j++) {
var itemId = itemResults[j].getValue('internalid');
var saveSoldOut = markAsSoldOut(orderInfo, itemId);
var saveInactivate = inactivateItems(orderInfo, itemId);
}
}
}
} catch (e) {
var subject = 'General Error ';
var body = 'There has been an error in ';
var recipients = ['example@example'];
email.send({
author: 349571,
recipients: recipients,
subject: subject,
body: body
});
}
}
return {
execute: execute,
};
});
希望这对您有所帮助。如果您有其他问题,请随时提出。
英文:
I'm trying to upload this script to NetSuite to start testing it, and it's giving me this error: SuiteScript 2.x entry point scripts must implement one script type function. It's a scheduled script, so the only entry point it should have is the execute function. Is there a syntax error I'm not seeing, or does anyone have a solution to this? I haven't found any solutions for this out there for a scheduled script. This is the script:
/**
* This script looks for originals sold, and marks the parent, child,
* and kit as sold out when the sales order is approved,
* and inactivates the parent, child, and kit when fulfilled.
*
* @NApiVersion 2.x
* @NScriptType ScheduledScript
* @NModuleScope SameAccount
*/
define(['N/search', 'N/record', 'N/log'], function (search, record, log) {
function createSoldOriginalSearch() {
return search.create({
type: "salesorder",
filters: [
["type", "anyof", "SalesOrd"],
"AND",
["item.custitemitemoriginal", "is", "T"],
"AND",
["item.isinactive", "is", "F"],
"AND",
["datecreated", "within", "lastmonth"]
],
columns: [
"statusref",
"shiprecvstatusline",
search.createColumn({
name: "type",
join: "item"
}),
search.createColumn({
name: "formulatext",
formula: "CASE WHEN {item.type}='Kit/Package' THEN SUBSTR({item.memberitem}, 0, 6) ELSE SUBSTR({item}, 0, 6) END"
}),
"internalid"
]
});
}
function getAllResults(searchObj) {
var start = 0;
var allResults = [];
var results = [];
var resultSet = searchObj.run();
results = resultSet.getRange({
start: start,
end: start + 1000
});
allResults = allResults.concat(results);
while (results.length) {
start += 1000;
results = resultSet.getRange({
start: start,
end: start + 1000
});
allResults = allResults.concat(results);
}
return allResults;
}
function getOrderInfo(results, index) {
var orderInfo = {};
orderInfo.id = results[index].id;
orderInfo.SOInternalId = results[index].getValue('internalid');
orderInfo.masterItemNum = results[index].getValue('formulatext');
orderInfo.SOStatus = results[index].getText('statusref');
orderInfo.itemFulfillStatus = results[index].getText('shiprecvstatusline');
return orderInfo;
}
function getItemIds(orderInfo) {
var searchFilter = search.createFilter({
name: 'itemid',
operator: search.Operator.CONTAINS,
values: orderInfo.masterItemNum
});
var inventorySearch = search.create({
type: search.Type.ITEM,
filters: [searchFilter],
columns: ['internalid']
});
var itemSearchResults = inventorySearch.run().getRange({
start: 0,
end: 1000 // Change this value to retrieve more or fewer results.
});
return itemSearchResults;
}
function markAsSoldOut(orderInfo, itemId) {
var itemRecord = record.load({
type: record.Type.SERIALIZED_INVENTORY_ITEM,
id: itemId,
});
if (orderInfo.SOStatus !== 'Pending Approval' && orderInfo.SOStatus !== 'Closed' && orderInfo.SOStatus !== 'Cancelled') {
itemRecord.setValue({
fieldId: 'custitemsold_out',
value: true,
});
}
var saveSoldOut = record.save();
return saveSoldOut;
}
function inactivateItems(orderInfo, itemId) {
var itemRecord = record.load({
type: record.Type.SERIALIZED_INVENTORY_ITEM, // Assuming you want to inactivate the item record
id: itemId,
});
if (orderInfo.itemFulfillStatus == 'true') {
itemRecord.setValue({
fieldId: 'isinactive',
value: true,
});
}
var saveInactivate = record.save();
return saveInactivate;
}
function execute(context) {
try {
var soldOriginalSearch = createSoldOriginalSearch();
var results = getAllResults(soldOriginalSearch);
log.debug('initial results', results);
for (var i = 0; i < results.length; i++) {
var orderInfo = getOrderInfo(results, i);
log.debug('orderinfo', orderInfo);
var itemResults = getItemIds(orderInfo);
if (itemResults && itemResults.length > 0) {
for (var j = 0; j < itemResults.length; j++) {
var itemId = itemResults[j].getValue('internalid');
var saveSoldOut = markAsSoldOut(orderInfo, itemId);
var saveInactivate = inactivateItems(orderInfo, itemId);
}
}
}
} catch (e) {
var subject = 'General Error ';
var body = 'There has been an error in ;
var recipients = ['example@example'];
email.send({
author: 349571,
recipients: recipients,
subject: subject,
body: body
});
}
}
return {
execute: execute,
};
});
I'm not sure if the script is fully functioning because it hasn't been tested, but I'd like to get it to a point it can be uploaded so I can test it.
答案1
得分: 1
以下是要翻译的内容:
在以下这行代码中存在未终止的字符串:
var body = 'There has been an error in ;
当我尝试以此状态上传时,会出现不同的错误,所以我不确定它是否是你所遇到问题的原因,但当我更正为:
var body = 'There has been an error in';
它可以顺利上传。
英文:
There's an unterminated string in the following line:
var body = 'There has been an error in ;
When I attempt to upload with this as is, I get a different error, so I'm not sure if it's the cause of what you're experiencing, but when I correct it to:
var body = 'There has been an error in';
it uploads without issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论