I want to create an search for the record using "SuitScript 2.0 version" . I know that i can achieve it using "SuiteScript 1.0" using nlapiSearchRecord() api using filters and conditions but i want do this with SuitScript 2.0 version. To this in "SuiteScript 2.0 " the "N/search Module" have to be used but not getting how to did the search in 2.0 in equivalent to suitscript 1.0 version.
Could any one give an example for the search in SuiteScript 2.0 version.
Thanks in Advance.
I want to create an search for the record using "SuitScript 2.0 version" . I know that i can achieve it using "SuiteScript 1.0" using nlapiSearchRecord() api using filters and conditions but i want do this with SuitScript 2.0 version. To this in "SuiteScript 2.0 " the "N/search Module" have to be used but not getting how to did the search in 2.0 in equivalent to suitscript 1.0 version.
Could any one give an example for the search in SuiteScript 2.0 version.
Thanks in Advance.
Share Improve this question edited Jul 14, 2016 at 6:19 Deepan Murugan asked Jul 14, 2016 at 5:01 Deepan MuruganDeepan Murugan 7713 gold badges22 silver badges42 bronze badges1 Answer
Reset to default 14You are correct that you will use N/search
. It uses an analogous API to the 1.0 API of nlapiCreateSearch
.
You will use search.create
to build out your search object or search.load
to load a saved search. Then you will invoke run
on the resulting search object. Finally, you can process the results in two ways:
- Use the
each
method and a callback - Use the
getRange
method to get a specific number of results
In the example below, I've imported N/search
into my module as s
and shown the usage of the each
method.
function findCustomers() {
// Create and run search
s.create({
"type": "customer",
"filters": [
['isinactive', s.Operator.IS, 'F'], 'and',
['pany', s.Operator.NONEOF, ['123','456']
],
"columns": ['email', 'firstname', 'lastname']
}).run().each(processCustomer);
}
function processCustomer(result) {
// do something with Customer search result
// returns a boolean; true to continue iterating, false to stop
return true;
}