如何在 SuiteScript 2.0 版本中创建搜索
How to create a Search in SuiteScript 2.0 version
我想使用 "SuitScript 2.0 version" 创建记录搜索。我知道我可以使用 "SuiteScript 1.0" 使用 nlapiSearchRecord() api 使用过滤器和条件来实现它,但我想用 SuitScript 2.0 来实现版本。
为此,在 "SuiteScript 2.0 " 中必须使用 "N/search Module" 但不知道如何在 2.0 中进行搜索,相当于 suitscript 1.0 版本。
谁能举个SuiteScript 2.0版本的搜索例子
提前致谢。
您说得对,您将使用 N/search
。它使用与 nlapiCreateSearch
.
的 1.0 API 类似的 API
您将使用 search.create
构建您的搜索对象或 search.load
加载已保存的搜索。然后您将对生成的搜索对象调用 run
。最后,您可以通过两种方式处理结果:
- 使用
each
方法和回调
- 使用
getRange
方法获取特定数量的结果
在下面的示例中,我将 N/search
作为 s
导入到我的模块中,并显示了 each
方法的用法。
function findCustomers() {
// Create and run search
s.create({
"type": "customer",
"filters": [
['isinactive', s.Operator.IS, 'F'], 'and',
['company', 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;
}
我想使用 "SuitScript 2.0 version" 创建记录搜索。我知道我可以使用 "SuiteScript 1.0" 使用 nlapiSearchRecord() api 使用过滤器和条件来实现它,但我想用 SuitScript 2.0 来实现版本。 为此,在 "SuiteScript 2.0 " 中必须使用 "N/search Module" 但不知道如何在 2.0 中进行搜索,相当于 suitscript 1.0 版本。
谁能举个SuiteScript 2.0版本的搜索例子
提前致谢。
您说得对,您将使用 N/search
。它使用与 nlapiCreateSearch
.
您将使用 search.create
构建您的搜索对象或 search.load
加载已保存的搜索。然后您将对生成的搜索对象调用 run
。最后,您可以通过两种方式处理结果:
- 使用
each
方法和回调 - 使用
getRange
方法获取特定数量的结果
在下面的示例中,我将 N/search
作为 s
导入到我的模块中,并显示了 each
方法的用法。
function findCustomers() {
// Create and run search
s.create({
"type": "customer",
"filters": [
['isinactive', s.Operator.IS, 'F'], 'and',
['company', 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;
}