当通过用户界面创建销售订单时,NetSuite I希望将"Create“子列表项目字段设置为'DropShip‘。I还希望添加另一个"if”来检查自定义字段。
我找到了一篇关于设置该字段的SuiteAwners文章:
"通过SuiteScript将Create字段设置为null“应答Id: 35911我已经让Suitescript1.0工作了(我已经将'createpo‘设置为'DropShip',而我还不能和另一个if语句检查销售订单上的自定义字段)
这里是Suitescript1.0代码:
function beforeSubmit(type)
{
var count = nlapiGetLineItemCount('item');
for (i=1; i<= count; i++)
{
var currentContext = nlapiGetContext();
//setting of 'createpo' field only happens when the script is triggered via User Interface
//add other if conditions here, if needed
// 'createpo' values are Null, 'DropShip', or 'SpecOrd'
if((currentContext.getExecutionContext() == 'userinterface'))
{
nlapiSetLineItemValue('item', 'createpo', i, 'DropShip');
}
}
}我知道Suitescript1.0被废弃了,所以我很乐意在Suitescript2.0中重写它。幸运的是,,SuiteAwnsers文章也有相应的代码。
这里是Suitescript2.0代码
function beforeSubmit(type){
var count = objRecord.selectLine({
sublistId: 'item',
line: i
});
for (i=1; i<= count; i++) {
var currentContext = runtime.executionContext();
//setting of 'createpo' field only happens when the script is triggered via Web Services
//add other if conditions here, if needed
if((currentContext.getExecutionContext() == 'webservices')) {
objRecord.setSublistValue({
sublistId: 'item',
fieldId: 'createpo',
line: i,
value: null
});
}
}
}不幸的是,当我在Netsuite中创建一个新脚本时,它只给了我“Select1.0脚本类型”作为选项,而不是“Select2.0脚本类型”.
我知道这是一个有点长,所以如果你已经做到了如此远的掌声!总之,有两件事我需要帮助
1.如何在提交“在Suitescript 1.0上”之前添加一个"if“,检查销售订单上已归档的值
2. I如何使suitescript 2.0工作(包括“在提交前”检查销售订单上已归档的值的"if“)
只是让大家都知道我对脚本非常陌生,所以如果您有解决方案,请给出尽可能详细的
发布于 2022-06-23 23:03:04
首先,需要将脚本版本设置在脚本的顶部,以便将其识别为版本2:
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/接下来,对于您的脚本:
最后的脚本可能如下所示:
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define( ['N/runtime'], function(Runtime) {
function beforeSubmit(context){
// get record from context
var objRecord = context.newRecord;
// get item list line count
var count = objRecord.getLineCount({
sublistId: 'item'
});
// start for loop at 0. lines are 0 indexed
for (i = 0; i < count; i++) {
var currentContext = Runtime.executionContext();
//setting of 'createpo' field only happens when the script is triggered via Web Services
//add other if conditions here, if needed
if((currentContext.getExecutionContext() == 'webservices')) {
objRecord.setSublistValue({
sublistId: 'item',
fieldId: 'createpo',
line: i,
value: 'DropShip'
});
}
}
}
return {
beforeSubmit: beforeSubmit
};});
希望这至少能让你开始。这个问题有点让人困惑,但这应该会让您开始使用一个功能2.0脚本。
https://stackoverflow.com/questions/72661835
复制相似问题