【问题标题】:SuiteScript - Unexpected Error Record.Save()SuiteScript - 意外错误 Record.Save()
【发布时间】:2022-07-30 03:28:53
【问题描述】:

由于某种原因,我在执行 caseRecord.save() 时收到错误消息。我不知道我是否遗漏了某些内容,但我已经多次查看,似乎无法弄清楚为什么我无法保存新创建的记录。

基本上,每当创建和批准 RMA 时,我都会创建一个支持案例。有人可以看一下代码,看看我是否遗漏了什么?


/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */
define(["N/format", "N/log", "N/record", "N/search"], /**
 * @param{format} format
 * @param{log} log
 * @param{record} record
 * @param{search} search
 */ (format, log, record, search) => {
  /**
   * Defines the function definition that is executed before record is loaded.
   * @param {Object} context
   * @param {Record} context.newRecord - New record
   * @param {string} context.type - Trigger type; use values from the context.UserEventType enum
   * @param {Form} context.form - Current form
   * @param {ServletRequest} context.request - HTTP request information sent from the browser for a client action only.
   * @since 2015.2
   */
  const beforeLoad = (context) => {};

  /**
   * Defines the function definition that is executed before record is submitted.
   * @param {Object} context
   * @param {Record} context.newRecord - New record
   * @param {Record} context.oldRecord - Old record
   * @param {string} context.type - Trigger type; use values from the context.UserEventType enum
   * @since 2015.2
   */
  const beforeSubmit = (context) => {
    const currentRecord = context.newRecord;
    const status = currentRecord.getValue({ fieldId: "orderstatus" });
    const customForm = currentRecord.getValue({ fieldId: "customform" });
    const customer = currentRecord.getValue({ fieldId: "entity" });
    const location = currentRecord.getValue({ fieldId: "location" });
    const salesOrderId = currentRecord.getValue({ fieldId: "custbody_originalsalesorder" });
    const rmaId = currentRecord.getValue({ fieldId: "id" });
    const salesRepId = currentRecord.getValue({ fieldId: "custbody_insidesalesrep" });
    const existingCase = currentRecord.getValue({ fieldId: "custbody_caseinternalid" });

    //Static Values
    const caseType = 9; //RMA
    const assignedTo = 6732844; 
    var existingPartNumber = null;

    log.debug({ title: "Context Type", details: context.type });
    log.debug({ title: "Current Record", currentRecord });
    log.debug({ title: "RMA ID", details: rmaId });

    if ((customForm != 266 || customForm != 269) && context.type == "approve") {
      if (existingCase == null || existingCase == undefined || existingCase == "") {
        log.debug({ title: "Action", details: "****START****" });
        const getLineCount = currentRecord.getLineCount({ sublistId: "item" });
        if (getLineCount > 0) {
          for (var i = 0; i < getLineCount; i++) {
            var invType = currentRecord.getSublistValue({ sublistId: "item", fieldId: "itemtype", line: i });
            //First Loop to get the location & class from the inventory item.
            if (invType == "InvtPart" || invType == "Assembly") {
              existingPartNumber = currentRecord.getSublistValue({ sublistId: "item", fieldId: "item", line: i });
              log.debug({
                title: "Invntory Item",
                details: "Located inventory item on line number " + (i + 1) + ". Grabbing values.",
              });
              break;
            }
          }

          log.debug({ title: "Action", details: "Starting Case Creation" });

          var caseRecord = record.create({
            type: record.Type.SUPPORT_CASE,
            isDynamic: true,
          });

          log.debug({ title: "Action", details: "Case Creation" });

          caseRecord.setValue({ fieldId: "customform", value: 49 });
          caseRecord.setValue({ fieldId: "category", value: caseType });
          caseRecord.setValue({ fieldId: "assigned", value: assignedTo });
          caseRecord.setValue({ fieldId: "custevent_caselocation", value: location });
          caseRecord.setValue({ fieldId: "company", value: customer });
          caseRecord.setValue({ fieldId: "item", value: existingPartNumber });
          caseRecord.setValue({ fieldId: "custevent_existingpartlink", value: existingPartNumber });
          caseRecord.setValue({ fieldId: "custevent_salesorder", value: salesOrderId });
          caseRecord.setValue({ fieldId: "custevent_rmarecord", value: rmaId });
          caseRecord.setValue({ fieldId: "custevent_salesrep", value: salesRepId });

          log.debug({ title: "Action", details: "Case values have been set" });

          var caseId = caseRecord.save({
            enableSourcing: true,
            ignoreMandatoryFields: true,
          });

          log.debug({ title: "Case ID", details: caseId });

          currentRecord.setValue({ fieldId: "custbody_caseinternalid", value: caseId });

          log.debug({ title: "Action", details: "****END****" });
        }
      } else {
        log.debug({ title: "Existing Case", details: "This record already hase a case assigned." });
      }
    } else if (status == "A") {
      log.debug({ title: "Record Status", details: "Record needs to be approved to create case" });
    } else {
      log.debug({ title: "Custom Form", details: `The form that was used is restricted. Form: ${customForm}` });
    }
  };

  /**
   * Defines the function definition that is executed after record is submitted.
   * @param {Object} context
   * @param {Record} context.newRecord - New record
   * @param {Record} context.oldRecord - Old record
   * @param {string} context.type - Trigger type; use values from the context.UserEventType enum
   * @since 2015.2
   */
  const afterSubmit = (context) => {};

  return { beforeLoad, beforeSubmit, afterSubmit };
});


错误

{
"type": "error.SuiteScriptError",
"name": "UNEXPECTED_ERROR",
"message": "An unexpected SuiteScript error has occurred",
"stack": [
"Error\n at RecordInvoker.save (suitescript/resources/javascript/record/serverRecordService.js:371:13)\n at NetSuiteObject.thenableFunction() (suitescript/resources/javascript/record/proxy.js:74:24)\n at Object.beforeSubmit (/SuiteScripts/Production Files/2.0 Converted Scripts/epec_ue_rma_create_case.js:102:35)"
],
"cause": {
"type": "internal error",
"code": "UNEXPECTED_ERROR",
"details": "An unexpected SuiteScript error has occurred",
"userEvent": null,
"stackTrace": [
"Error\n at RecordInvoker.save (suitescript/resources/javascript/record/serverRecordService.js:371:13)\n at NetSuiteObject.thenableFunction() (suitescript/resources/javascript/record/proxy.js:74:24)\n at Object.beforeSubmit (/SuiteScripts/Production Files/2.0 Converted Scripts/epec_ue_rma_create_case.js:102:35)"
],
"notifyOff": false
},
"id": "",
"notifyOff": false,
"userFacing": true
}

【问题讨论】:

  • 案例记录中是否有任何可能引发错误的用户事件脚本或工作流?

标签: netsuite suitescript user-event


【解决方案1】:

从代码中抛出的异常在哪里?所以我想我的问题是最后打印的日志是什么?或者第一个不打印的。

【讨论】:

  • 这篇文章看起来不像是试图回答这个问题。这里的每一篇文章都应该明确地尝试回答这个问题;如果您有批评或需要澄清问题或其他答案,您可以在其下方直接post a comment(如这个)。请删除此答案并创建评论或新问题。见:Ask questions, get answers, no distractions
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多