如何在SuiteScrip 2.0版本中创建搜索

人气:448 发布:2022-10-16 标签: search javascript json netsuite suitescript

问题描述

我要使用"SuitScript 2.0版本"创建记录搜索。我知道我可以使用"SuiteScrip 1.0"使用使用筛选器和条件的nlip iSearchRecord()API来实现它,但我希望使用SuitScrip 2.0版本来实现。 为此,在"SuiteScrip 2.0"中,必须使用"N/Search模块",但不知道如何在相当于SuitSCRIPT 1.0版本的2.0中进行搜索。

谁能举一个在SuiteScrip 2.0版本中进行搜索的例子。

提前谢谢。

推荐答案

您说得对,您将使用N/search。它使用的接口类似于nlapiCreateSearch的1.0接口。

您将使用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;
}

926