nlapi allows to use joins to refer to values in another record or a sublist, when searching for a record. E.g. if there is a record FOO
FOO: {
type: 'rectype',
field1: '111',
sublists:
bar: [
{value: 1,}, {value: 2,}
]
}
I can search for this record with a query, provided there is a join, let's say, bar to the bar sublits:
nlapiSearchRecord('rectype', null,
[
['field', 'equalto', 'bar',],
'and',
['bar.value', 'equalto', '1',],
],
[ new nlobjSearchColumn('anotherfield', null, null), ]
);
This works. And the question is: is there a way to find a record (the one from the example) by specifying more sublist values, like:
nlapiSearchRecord('rectype', null,
[
['field', 'equalto', 'bar',],
'and',
['bar.value', 'equalto', '1',],
'and',
['bar.value', 'equalto', '2',],
],
[ new nlobjSearchColumn('anotherfield', null, null), ]
);
I've tried numerous approaches with different expressions, but it finds nothing with such a query.
A more concrete example is to find a bomrevision, which has specific components and bomquantities (the commented code is just for demonstration purposes of some approaches with the filter expression I've tried):
nlapiSearchRecord('bomrevision', null, [
['isinactive', 'equalto', 'F',],
'and',
['component.item', 'is', '4942',],
'and',
['component.item', 'is', '4936',],
//[
// 'and',
// ['component.bomquantity', 'equalto', '38',],
//],
//'and',
//[
// ['component.item', 'anyof', '4936',],
// 'and',
// ['component.bomquantity', 'equalto', '38',],
//],
],
[ new nlobjSearchColumn('name', null, null), ]
);
Thank you
I understand your question to be "How can I find items where the component list includes multiple specified items?"
The challenge here is that when you join to the component list, NetSuite returns a result for each line in the list. This means any line that contains 'Item 1' will not contain 'Item 2' and vice versa, so no result meets the criteria.
You can work around this using the following approach:
NS_CONCATto give a field in each result that contains values from all the sublist results. (Note thatNS_CONCATis undocumented, so use at your own risk).Example (tested with assembly items and their member items as I don't have access to an account with BOM revisions):
Or, for your 'bomrevision' (untested, adapted from above):
Be aware that under some circumstances NetSuite will default to returning the text of a list field rather than the value. If this is the case (and the values shown in your example are internal IDs as I'm assuming), you may need to replace
component.itemwithcomponent.item.id, or change the search values to the text name instead.There may be a more straightforward way of doing this so I'd be glad to hear from anyone with a better solution.
Edit in response to request in comments:
Here is the full code of a working example in my account:
This is an Item search filtering by Member Items, as the closest thing in my account to the BOM Revisions in the example. The only change I have made is to replace the item names with "ITEM 1" and "ITEM 2". You would need to replace these with relevant items from your system.
I can go to a Sales Order page and open developer tools on my browser and add the above code to create a search, then append the following additional code to retrieve results and print out to the console:
This returns a table with results exactly as expected.
Edit 2: Adding example using Sales Orders and Items as possibly more consistent between different accounts.