套件 - 意外错误记录。Save()
由于某种原因,当执行caseRecord.save.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
}
For some reason, I am receiving an error when caseRecord.save()
is executed. I am unaware if I have missed something but I have looked over this multiple times and can't seem to figure out why I am unable to save the newly created record.
Basically, I am creating a support case whenever an RMA is created and approved. Can someone take a look at the code to see if I missed anything?
/**
* @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 };
});
Error
{
"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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论