【问题标题】:NetSuite SuiteScript 2 - Access sublist via SearchNetSuite SuiteScript 2 - 通过搜索访问子列表
【发布时间】:2018-08-21 13:09:53
【问题描述】:

我正在搜索给定日期范围内的客户付款,我需要获取已为每个客户付款支付的发票的发票参考号。发票参考号位于子列表 apply 下,其中 apply 字段设置为 true。

我会放一些代码/有效负载:

    search.create({           
        type: search.Type.CUSTOMER_PAYMENT,
        filters: [['lastmodifieddate', 'within', context.from_datetime, context.to_datetime]],
        columns: [
                'entity',
                'status',
            ]
    }).run().forEach(function(result) {
         // Do stuff
    });

这是客户支付负载的(短版):

{
"id": "103",
"type": "customerpayment",
"isDynamic": false,
"fields": {
    // payment main fields
},
"sublists": {
    // Other sublists
    "apply": {
        "line 1": {
            "apply": "T",
            "currency": "GBP",
            "refnum": "TEST-00002",
            // Other fields
        },
        "line 2": {
            "apply": "F",
            "currency": "GBP",
            "refnum": "TEST-00001",
            // Other fields            
        }
    }
}

所以,在搜索列数组中,我想从 apply 字段为 T 的行项目中获取 refnum 字段。(在这种情况下应该返回 TEST-00002) 抓取整个应用子列表也足够了,然后我将计算出循环到对象中的引用句柄。

我要避免的是每次都加载付款记录,因为它会减慢搜索速度。

这可能吗?任何人都可以帮忙吗? 非常感谢!

【问题讨论】:

    标签: javascript netsuite suitescript


    【解决方案1】:

    我相信您正在寻找的是“应用于交易”字段。您可以通过列表底部的 UI 中的连接或通过如下所示的 SuiteScript 访问这些。在我的帐户中,引用句柄字段与 Applied To 交易的文档编号相同,因此我可以通过以下方式获取编号:

    var customerpaymentSearchObj = search.create({
       type: "customerpayment",
       filters:
       [
          ["type","anyof","CustPymt"],
       ],
       columns:
       [
          "tranid",
          "entity",
          "amount",
          "appliedtotransaction",
          "appliedtolinkamount",
          "appliedtolinktype",
          search.createColumn({
             name: "tranid",
             join: "appliedToTransaction"
          }) // <--- This is the one
       ]
    });
    customerpaymentSearchObj.run().each(function(result){
       // .run().each has a limit of 4,000 results
       var refnum = result.getValue({ name: 'tranid', join: 'appliedToTransaction' });
       return true;
    });
    

    【讨论】:

    • appliedtotransaction 不是记录浏览器中的字段,所以我不明白这里发生了什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 2016-01-14
    • 2021-11-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多