I am trying to add a filter in the search condition.
The problem I am facing is that while I am using the internalid and the int 1111 it works fine. But if i replace with some other column with string it does not work. It throws error in cust search line. Can anyone suggest ?
var custSearch = search.create({
type : record.Type.CUSTOMER,
columns : searchColumn,
filters: [
'email', 'ANYOF', ["[email protected]","[email protected]"]]
//'internalid', 'ANYOF', ["1397","1251"]] // Works fine
});
custSearch.run().each(function(result) { // throw errors
log.debug("Found !",result);
return true;
});
I am trying to add a filter in the search condition.
The problem I am facing is that while I am using the internalid and the int 1111 it works fine. But if i replace with some other column with string it does not work. It throws error in cust search line. Can anyone suggest ?
var custSearch = search.create({
type : record.Type.CUSTOMER,
columns : searchColumn,
filters: [
'email', 'ANYOF', ["[email protected]","[email protected]"]]
//'internalid', 'ANYOF', ["1397","1251"]] // Works fine
});
custSearch.run().each(function(result) { // throw errors
log.debug("Found !",result);
return true;
});
Share
Improve this question
asked Jul 5, 2017 at 16:52
ArindamArindam
72310 silver badges19 bronze badges
0
3 Answers
Reset to default 5Email field is not patible with ANYOF operator. Try any of the following:
- ANY
- IS
- ISEMPTY
- STARTSWITH
- CONTAINS
- ISNOT
- ISNOTEMPTY
- DOESNOTSTARTWITH
- DOESNOTCONTAIN
If you need to filter by multiple emails then you could use expressions to add "OR"s. I suggest using the Chrome extension Netsuite: Search Export to make things easier.
function stringFieldAnyOf(fieldId, listOfValues) {
var result = [];
if (listOfValues.length > 0) {
for (var i = 0; i < listOfValues.length; i++) {
result.push([fieldId, 'startswith', listOfValues[i]]);
result.push('or');
}
result.pop(); // remove the last 'or'
}
return result;
}
// usage: (two more filters added just to illustrate how to bine with other filters)
var custSearch = search.create({
type: record.Type.CUSTOMER,
columns: searchColumn,
filters: [
['panyname', 'startswith', 'A'], 'and',
stringFieldAnyOf('email', ['[email protected]', '[email protected]']), 'and',
['panyname', 'contains', 'b']
]
});
options.filters that you are using could be:
- a single search.Filter object
- an array of search.Filter objects
- a search filter expression
- an array of search filter expressions
In your example, you create 2 Filter Objects (filterscust1 and filterscust2). After that you try to create a search filter expression, bining two Filter Objects with 'or' string inside. But this is not correct:
A search filter expression is a JavaScript string array of zero or more elements. Each element is one of the following:
- Operator - either ‘NOT', ‘AND', or ‘OR'
- Filter term
- Nested search filter expression
So, the equivalent code should be:
filterscust1 = ['email', 'contains', '[email protected]'];
filterscust2 = ['email', 'contains', '[email protected]'];
var filtersExp = [ filterscust1, 'or', filterscust2 ];
var custSearch = search.create({
type: record.Type.CUSTOMER,
columns: searchColumn,
filters: [filtersExp]
});
or directly:
var custSearch = search.create({
type: record.Type.CUSTOMER,
columns: searchColumn,
filters: [ ['email', 'contains', '[email protected]'], 'or',
['email', 'contains', '[email protected]']
]
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744109383a4558879.html
评论列表(0条)