I'm performing a search on customer payments with a given date range, and I need to fetch the invoice reference number of the invoice that has been paid for each customer payment. The invoice reference number is under the sublist apply where the field apply is set to true.
I'll put some piece of code/payload:
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
});
And this is a (short version) of a customer payment payload:
{
"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
}
}
}
So, in the search columns array, I want to grab the refnum field from the line item where the apply field is T. (in this case should return TEST-00002)
It's good enough also to grab the whole apply sublist, then I'll work out the refnum looping into the object.
What I want to avoid is to load every time the payment record as it's going to slow down the search.
Is this possible? Anyone can help? Thanks a lot!