项目履行发票
item fulfillment to invoice
我正在尝试将项目履行转换为发票。我创建了一个名为 "freight cost" and I"m trying to get the value of that field and transfer it over to the invoice and add two lines to the item sublist: "FREIGHT" 和 "HANDLING" 的自定义字段。但是,当我尝试获取运费的值时出现错误。
这是我的代码:
/**
* @NApiVersion 2.x
* @NScriptType 用户事件脚本
* @NModuleScope 相同帐户
*/
定义(['N/record','N/log'],
函数(记录,日志){
function afterSubmit(context) {
var orderId = context.newRecord;
var freightCost = orderId.record.getValue({
fieldId:'custbody_freight_cost'
});
log.error({
title: 'Freight Cost',
details: freightCost
});
var invoiceRecord = record.transform({
fromType: record.Type.ITEM_FULFILLMENT,
fromId: orderId,
toType: record.Type.INVOICE,
isDynamic: true
});
log.error({
title: 'Debug Entry',
details: invoiceRecord
});
var freightLine = invoiceRecord.insertLine({
sublistId:'item',
item: 3,
ignoreRecalc: true
});
var handlingLine = invoiceRecord.insertLine({
sublistId:'item',
item: 4,
ignoreRecalc: true
});
var freightSaver = invoiceRecord.setCurrentSublistValue({
sublistId:'item',
fieldId:'custbody_freight_cost',
value: freightCost,
ignoreFieldChange: true
});
var rid = invoiceRecord.save();
}
return {
afterSubmit: afterSubmit
};
});
这是我遇到的错误:
org.mozilla.javascript.EcmaError: TypeError: 无法调用未定义的方法 "getValue" (/SuiteScripts/complexInvoice.js#12)
您收到该错误的原因是您在 record
对象而不是 orderId
对象上调用 .getValue
方法。我建议重命名您的变量以避免一些混淆,就像我在下面所做的那样。
我发现此脚本中出现的另一个问题是,不允许您在 SuiteScript 中将 Item Fulfillment 转换为 Invoice。您只能将销售订单转换为发票。如果您想查看可以在 SuiteScript 中进行的所有可能的转换,请打开 NetSuite 帮助并搜索 record.transform(options)
.
最后,您似乎以一种不寻常的方式向新发票添加了子列表行。有关如何在 "dynamic" 模式下向发票记录添加行的示例,请参阅下面的代码。
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(["N/record", "N/log"], function (record, log) {
function afterSubmit(context) {
// Gather your variables
var newRec = context.newRecord;
var freightCost = newRec.getValue({
fieldId: 'custbody_freight_cost'
});
var salesOrderId = newRec.getValue({ // Here we are getting the sales order id to use in the transform function
fieldId: 'createdfrom'
});
log.error({
title: 'Freight Cost',
details: freightCost
});
// Transform the Sales Order into an Invoice
var invoiceRecord = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: salesOrderId,
toType: record.Type.INVOICE,
isDynamic: true
});
log.error({
title: 'Debug Entry',
details: invoiceRecord
});
// Add lines to the invoice like this, this is the correct way when the record is in "dynamic" mode
invoiceRecord.selectNewLine({
sublistId: 'item'
});
invoiceRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: 3
});
invoiceRecord.commitLine({
sublistId: 'item'
});
invoiceRecord.selectNewLine({
sublistId: 'item'
});
invoiceRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: 4
});
invoiceRecord.commitLine({
sublistId: 'item'
});
// Here is how you set a body field
invoiceRecord.setValue({
fieldId: 'custbody_freight_cost',
value: freightCost,
ignoreFieldChange: true
});
// Submit the record
var rid = invoiceRecord.save();
log.debug('Saved Record', rid);
}
return { afterSubmit: afterSubmit };
});
我正在尝试将项目履行转换为发票。我创建了一个名为 "freight cost" and I"m trying to get the value of that field and transfer it over to the invoice and add two lines to the item sublist: "FREIGHT" 和 "HANDLING" 的自定义字段。但是,当我尝试获取运费的值时出现错误。
这是我的代码:
/** * @NApiVersion 2.x * @NScriptType 用户事件脚本 * @NModuleScope 相同帐户 */ 定义(['N/record','N/log'],
函数(记录,日志){
function afterSubmit(context) {
var orderId = context.newRecord;
var freightCost = orderId.record.getValue({
fieldId:'custbody_freight_cost'
});
log.error({
title: 'Freight Cost',
details: freightCost
});
var invoiceRecord = record.transform({
fromType: record.Type.ITEM_FULFILLMENT,
fromId: orderId,
toType: record.Type.INVOICE,
isDynamic: true
});
log.error({
title: 'Debug Entry',
details: invoiceRecord
});
var freightLine = invoiceRecord.insertLine({
sublistId:'item',
item: 3,
ignoreRecalc: true
});
var handlingLine = invoiceRecord.insertLine({
sublistId:'item',
item: 4,
ignoreRecalc: true
});
var freightSaver = invoiceRecord.setCurrentSublistValue({
sublistId:'item',
fieldId:'custbody_freight_cost',
value: freightCost,
ignoreFieldChange: true
});
var rid = invoiceRecord.save();
}
return {
afterSubmit: afterSubmit
};
});
这是我遇到的错误:
org.mozilla.javascript.EcmaError: TypeError: 无法调用未定义的方法 "getValue" (/SuiteScripts/complexInvoice.js#12)
您收到该错误的原因是您在 record
对象而不是 orderId
对象上调用 .getValue
方法。我建议重命名您的变量以避免一些混淆,就像我在下面所做的那样。
我发现此脚本中出现的另一个问题是,不允许您在 SuiteScript 中将 Item Fulfillment 转换为 Invoice。您只能将销售订单转换为发票。如果您想查看可以在 SuiteScript 中进行的所有可能的转换,请打开 NetSuite 帮助并搜索 record.transform(options)
.
最后,您似乎以一种不寻常的方式向新发票添加了子列表行。有关如何在 "dynamic" 模式下向发票记录添加行的示例,请参阅下面的代码。
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(["N/record", "N/log"], function (record, log) {
function afterSubmit(context) {
// Gather your variables
var newRec = context.newRecord;
var freightCost = newRec.getValue({
fieldId: 'custbody_freight_cost'
});
var salesOrderId = newRec.getValue({ // Here we are getting the sales order id to use in the transform function
fieldId: 'createdfrom'
});
log.error({
title: 'Freight Cost',
details: freightCost
});
// Transform the Sales Order into an Invoice
var invoiceRecord = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: salesOrderId,
toType: record.Type.INVOICE,
isDynamic: true
});
log.error({
title: 'Debug Entry',
details: invoiceRecord
});
// Add lines to the invoice like this, this is the correct way when the record is in "dynamic" mode
invoiceRecord.selectNewLine({
sublistId: 'item'
});
invoiceRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: 3
});
invoiceRecord.commitLine({
sublistId: 'item'
});
invoiceRecord.selectNewLine({
sublistId: 'item'
});
invoiceRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: 4
});
invoiceRecord.commitLine({
sublistId: 'item'
});
// Here is how you set a body field
invoiceRecord.setValue({
fieldId: 'custbody_freight_cost',
value: freightCost,
ignoreFieldChange: true
});
// Submit the record
var rid = invoiceRecord.save();
log.debug('Saved Record', rid);
}
return { afterSubmit: afterSubmit };
});