Scheduled Script Error: SuiteScript 2.x入口脚本必须实现一个脚本类型函数

huangapple go评论68阅读模式
英文:

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([&#39;N/search&#39;, &#39;N/record&#39;, &#39;N/log&#39;], function (search, record, log) {
function createSoldOriginalSearch() {
return search.create({
type: &quot;salesorder&quot;,
filters: [
[&quot;type&quot;, &quot;anyof&quot;, &quot;SalesOrd&quot;],
&quot;AND&quot;,
[&quot;item.custitemitemoriginal&quot;, &quot;is&quot;, &quot;T&quot;],
&quot;AND&quot;,
[&quot;item.isinactive&quot;, &quot;is&quot;, &quot;F&quot;],
&quot;AND&quot;,
[&quot;datecreated&quot;, &quot;within&quot;, &quot;lastmonth&quot;]
],
columns: [
&quot;statusref&quot;,
&quot;shiprecvstatusline&quot;,
search.createColumn({
name: &quot;type&quot;,
join: &quot;item&quot;
}),
search.createColumn({
name: &quot;formulatext&quot;,
formula: &quot;CASE WHEN {item.type}=&#39;Kit/Package&#39; THEN SUBSTR({item.memberitem}, 0, 6) ELSE SUBSTR({item}, 0, 6) END&quot;
}),
&quot;internalid&quot;
]
});
}
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(&#39;internalid&#39;);
orderInfo.masterItemNum = results[index].getValue(&#39;formulatext&#39;);
orderInfo.SOStatus = results[index].getText(&#39;statusref&#39;);
orderInfo.itemFulfillStatus = results[index].getText(&#39;shiprecvstatusline&#39;);
return orderInfo;
}
function getItemIds(orderInfo) {
var searchFilter = search.createFilter({
name: &#39;itemid&#39;,
operator: search.Operator.CONTAINS,
values: orderInfo.masterItemNum
});
var inventorySearch = search.create({
type: search.Type.ITEM,
filters: [searchFilter],
columns: [&#39;internalid&#39;]
});
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 !== &#39;Pending Approval&#39; &amp;&amp; orderInfo.SOStatus !== &#39;Closed&#39; &amp;&amp; orderInfo.SOStatus !== &#39;Cancelled&#39;) {
itemRecord.setValue({
fieldId: &#39;custitemsold_out&#39;,
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 == &#39;true&#39;) {
itemRecord.setValue({
fieldId: &#39;isinactive&#39;,
value: true,
});
}
var saveInactivate = record.save();
return saveInactivate;
}
function execute(context) {
try {
var soldOriginalSearch = createSoldOriginalSearch();
var results = getAllResults(soldOriginalSearch);
log.debug(&#39;initial results&#39;, results);
for (var i = 0; i &lt; results.length; i++) {
var orderInfo = getOrderInfo(results, i);
log.debug(&#39;orderinfo&#39;, orderInfo);
var itemResults = getItemIds(orderInfo);
if (itemResults &amp;&amp; itemResults.length &gt; 0) {
for (var j = 0; j &lt; itemResults.length; j++) {
var itemId = itemResults[j].getValue(&#39;internalid&#39;);
var saveSoldOut = markAsSoldOut(orderInfo, itemId);
var saveInactivate = inactivateItems(orderInfo, itemId);
}
}
}
} catch (e) {
var subject = &#39;General Error &#39;;
var body = &#39;There has been an error in ;
var recipients = [&#39;example@example&#39;];
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 = &#39;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 = &#39;There has been an error in&#39;; 

it uploads without issue.

huangapple
  • 本文由 发表于 2023年8月5日 03:40:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76838757.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定