我正在搜索给定日期范围内的客户付款,我需要获取已为每次客户付款支付的发票的发票参考号。发票参考号位于子列表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
}
}
}
因此,在搜索列数组中,我想从refnum
字段为T的行项目中抓取apply
字段(在这种情况下应返回TEST-00002)
抓取整个apply子列表也足够好,然后我将把refnum循环到对象中。
我要避免的是每次付款记录都会加载,因为这会减慢搜索速度。
这可能吗?有人可以帮忙吗? 非常感谢!
答案 0 :(得分:1)
我相信您正在寻找的是“应用于交易”字段。您可以在列表底部的UI中或通过如下的SuiteScript将它们作为联接来访问。在我的帐户中,refnum字段与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;
});