首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将“创建PO”设置为下船

将“创建PO”设置为下船
EN

Stack Overflow用户
提问于 2022-06-17 15:46:58
回答 1查看 141关注 0票数 0

当通过用户界面创建销售订单时,NetSuite I希望将"Create“子列表项目字段设置为'DropShip‘。I还希望添加另一个"if”来检查自定义字段。

我找到了一篇关于设置该字段的SuiteAwners文章:

"通过SuiteScript将Create字段设置为null应答Id: 35911我已经让Suitescript1.0工作了(我已经将'createpo‘设置为'DropShip',而我还不能和另一个if语句检查销售订单上的自定义字段)

这里是Suitescript1.0代码:

代码语言:javascript
复制
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代码

代码语言:javascript
复制
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“)

只是让大家都知道我对脚本非常陌生,所以如果您有解决方案,请给出尽可能详细的

EN

回答 1

Stack Overflow用户

发布于 2022-06-23 23:03:04

首先,需要将脚本版本设置在脚本的顶部,以便将其识别为版本2:

代码语言:javascript
复制
 /**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */

接下来,对于您的脚本:

  1. 您的count没有得到一个行计数,而是选择了一个行,并且您正在将一个未实例化的var i传递到它。您需要使用record.getLineCount()代替: 变量计数= objRecord.getLineCount({ sublistId:'item‘});
  2. 在0处启动for循环。在文本2中,所有列表都是0索引的。 对于(i = 0;i< count;i++) {
  3. 由于要引用运行时模块,请确保它包含在定义语句中。

最后的脚本可能如下所示:

代码语言:javascript
复制
/**
* @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脚本。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72661835

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档