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:
- Group the results by 'main' or 'parent' record ('FOO' or 'bomrevision' in your examples).
- Use
NS_CONCAT
to give a field in each result that contains values from all the sublist results. (Note that NS_CONCAT
is undocumented, so use at your own risk).
- Use summary criteria formulae to inspect the concatenated field for each value of interest.
Example (tested with assembly items and their member items as I don't have access to an account with BOM revisions):
[
["type","anyof","Assembly"],
"AND",
["min(formulatext: NS_CONCAT({memberitem.name}) )","contains","ITEM 1"],
"AND",
["min(formulatext: NS_CONCAT({memberitem.name}))","contains","ITEM 2"]
]
Or, for your 'bomrevision' (untested, adapted from above):
[
["min(formulatext: NS_CONCAT({component.item}) )","contains","4942"],
"AND",
["min(formulatext: NS_CONCAT({component.item}))","contains","4936"]
]
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.item
with component.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:
var assemblyitemSearch = nlapiSearchRecord("assemblyitem",null,
[
["type","anyof","Assembly"],
"AND",
["min(formulatext: NS_CONCAT({memberitem.name}) )","contains","ITEM 1"],
"AND",
["min(formulatext: NS_CONCAT({memberitem.name}))","contains","ITEM 2"]
],
[
new nlobjSearchColumn("itemid",null,"GROUP").setSort(false),
new nlobjSearchColumn("displayname",null,"GROUP"),
new nlobjSearchColumn("salesdescription",null,"GROUP"),
new nlobjSearchColumn("formulatext",null,"MIN").setFormula("NS_CONCAT({memberitem})")
]
);
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:
var data = [];
assemblyitemSearch.forEach(r => {
var vals = {};
r.rawValues.forEach(v => {
vals[v.name] = v.value
});
data.push(vals);
});
console.table(data);
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.
var salesorderSearch = nlapiSearchRecord("salesorder",null,
[
["type","anyof","SalesOrd"],
"AND",
["trandate","within","thismonth"],
"AND",
["min(formulatext: NS_CONCAT({item}))","contains","ITEM 1"],
"AND",
["min(formulatext: NS_CONCAT({item}))","contains","ITEM 2"]
],
[
new nlobjSearchColumn("trandate",null,"GROUP"),
new nlobjSearchColumn("tranid",null,"GROUP"),
new nlobjSearchColumn("formulatext",null,"MIN").setFormula("NS_CONCAT({item})")
]
);