简体   繁体   English

Netsuite:SuiteScript 2.0 - 获取最新的传输订单

[英]Netsuite: SuiteScript 2.0 - get latest transfer order

I am trying to add lines to a transfer order in Netsuite.我正在尝试向 Netsuite 中的转移订单添加行。 I want to add them on the latest order created between two specific locations.我想将它们添加到在两个特定位置之间创建的最新订单上。

I am trying this:我正在尝试这个:

    var s = search.create({
    type : search.Type.TRANSACTION,
    columns : ['internalid'],
    filters : [
              ["location","anyof","61"], 
              "AND", 
              ["transferlocation","anyof","62"], 
              "AND", 
              ["mainline","is","T"], 
              "AND", 
              ["trandate","on","today"]
              ]
        }); 
    
    var resultSet = s.run();
    var latestTO = resultSet[0];

But I get this error when I try adding a line to latestTO:但是当我尝试向 latestTO 添加一行时出现此错误:

{"type":"error.SuiteScriptError","name":"UNEXPECTED_ERROR","message":null,"stack":["anonymous(N/recordImpl)","onAction(/SuiteScripts/TEST.js:67)"],"cause":{"type":"internal error","code":"UNEXPECTED_ERROR","details":null,"userEvent":null,"stackTrace" {"type":"error.SuiteScriptError","name":"UNEXPECTED_ERROR","message":null,"stack":["anonymous(N/recordImpl)","onAction(/SuiteScripts/TEST.js:67 )"],"cause":{"type":"内部错误","code":"UNEXPECTED_ERROR","details":null,"userEvent":null,"stackTrace"

My script works if I "hardcode" the internalID of the latest transfer order.如果我对最新转移订单的 internalID 进行“硬编码”,我的脚本就可以工作。

Any ideas?有任何想法吗?

If you are trying to create a Saved Search to access Transfer Orders, you can use SORT BY function.如果您尝试创建一个已保存的搜索来访问转移订单,您可以使用SORT BY功能。 You can sort using Date Created in descending order.您可以使用“创建日期”按降序排序。

在此处输入图片说明

I would suggest you to create the Saved Search and test all your requirements.我建议您创建 Saved Search 并测试您的所有要求。 Later you can export this Saved Search as a script and use it in your code.稍后您可以将此保存的搜索导出为脚本并在您的代码中使用它。

In order to get the latest Transfer Order value, you simply need to include InternalID column in your results tab.为了获得最新的转移订单值,您只需在结果选项卡中包含 InternalID 列。

columns : ['internalid']

Later, you'll have to execute this Saved Search using script.稍后,您必须使用脚本执行此保存的搜索。

var s = search.create({
    type : search.Type.TRANSACTION,
    columns : ['internalid'],
    filters : [
              ["location","anyof","61"], 
              "AND", 
              ["transferlocation","anyof","62"], 
              "AND", 
              ["mainline","is","T"], 
              "AND", 
              ["trandate","on","today"]
              ]
        });


var searchResultCount = s.runPaged().count;
log.debug("s result count",searchResultCount);
s.run().each(function(result){
   // .run().each has a limit of 4,000 results
   return true;
});

var searchResult = s.run().getRange({start:0,end:999});

Variable searchResultCount stores the total number of results变量searchResultCount存储结果总数

Variable searchResult contains all the data变量searchResult包含所有数据

In order to get recently created TO, simply fetch the first value.为了获得最近创建的 TO,只需获取第一个值。

for(var j=0;j<1;j++) {
    var latestTO = searchResult[j].getValue({name:'internalid'});;
}

Variable latestTO will now have the internalID.变量 latestTO 现在将具有 internalID。 Use this to load the record.使用它来加载记录。

Let me know in case of any issues in the comment section.如果有任何问题,请在评论部分告诉我。

Another problem is if i hardcode my variabel latestTO, as:另一个问题是,如果我将我的变量 latestTO 硬编码为:

var latestTO = '1337'; var latestTO = '1337';

and make the update:并进行更新:

                            var TO = record.load({
                            type: 'transferOrder', 
                            id: latestTO,
                            isDynamic: true
                            });

Nothing happens.没发生什么事。

But if I do:但如果我这样做:

                            var TO = record.load({
                            type: 'transferOrder', 
                            id: 1337,
                            isDynamic: true
                            });

It works...有用...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM