javascript - 传递脚本参数
问题描述
我在为此代码传递脚本参数时遇到了一些麻烦。该代码似乎没有从该执行日志和错误消息中读取任何参数值:https ://photos.app.goo.gl/FXKYkFAXMctP4WhY6
/** * @NApiVersion 2.x * @NScriptType UserEventScript * @NModuleScope SameAccount */ define(["N/record", "N/log", "N/runtime"], function (record, log, runtime) {
function afterSubmit(context) {
// Gather your variables
var newRec = context.newRecord;
var freightCost = newRec.getValue({
fieldId: 'custbody_freight_cost'
});
var freightItem = runtime.getCurrentScript().getParameter('custscript_freight_item');
var handlingItem = runtime.getCurrentScript().getParameter('custscript_handling_item');
var salesOrderId = newRec.getValue({
fieldId: 'createdfrom'
});
log.debug('Sales Order ID', salesOrderId);
log.error({
title: 'Freight Cost',
details: freightCost
});
log.error({
title: 'Freight Item',
details: freightItem
});
// 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
});
invoiceRecord.selectNewLine({
sublistId: 'item'
});
invoiceRecord.setCurrentSublistText({
sublistId: 'item',
fieldId: 'item',
text: freightItem
});
invoiceRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'amount',
value: freightCost
});
invoiceRecord.commitLine({
sublistId: 'item'
});
invoiceRecord.selectNewLine({
sublistId: 'item'
});
invoiceRecord.setCurrentSublistText({
sublistId: 'item',
fieldId: 'item',
text: handlingItem
});
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
};
});
解决方案
您可以尝试将对象传递给getParameter
这样的函数吗?
var freightItem = runtime.getCurrentScript().getParameter({ name: 'custscript_freight_item' });
推荐阅读
- javascript - 是否可以在工作脚本上实现文档对象(或至少一部分)?如何?
- javascript - 我无法在我的 React + Redux 应用程序中使用 mapDispatchToProps
- php - 如何使用 Facebook 营销 api 更新 Facebook 活动详情
- python - 为什么不能优化这个简单的 oemof-model 呢?
- laravel - 在 Laravel 中自动递增 ID 回滚
- iis - web.config 为所有 html 文件设置标题
- ruby-on-rails - Rails 5.2 ActiveStorage 上传图片以及如何按用户裁剪图片
- c# - 安装 Microsoft.Azure.CosmosDB.Table NuGet 时出错
- hyperledger-fabric - Hyperledger 资源管理器始终显示为 3 个虚拟机上结构网络的 1 个节点,对等状态显示为关闭
- java - compileJava 不适用于本地库