George Huang
George Huang

Reputation: 5

NetSuite:I want to edit a savedSearch and saved it.But the filters of the savedSearch is null

The suitescript 1.0 code as follow:

function clientFieldChanged(type, name, linenum) {
if (name == 'class') {
    var brand_id = nlapiGetFieldValue('class');
    if (brand_id) {
        console.log(brand_id);
        var itemSearch = nlapiLoadSearch(null,'customsearch_item_brand_search');
        var itemSearchFilter = new nlobjSearchFilter('custitem30', null, 'anyof',brand_id);
        var filters = [itemSearchFilter];
        itemSearch.setFilters(filters);
        itemSearch.saveSearch();
    }
}

} But after this script is executed,the filters of the saved search is null.SuiteScript 1.0 saved Search

The suitescript 2.0 code as follow:

function fieldChanged(scriptContext) {
    if(scriptContext.fieldId == 'class'){
        var currentRecord = scriptContext.currentRecord;
        var brand_id = currentRecord.getValue({fieldId:'class'});
        if(brand_id){
            var itemSearch = search.load({
                id: 'customsearch_item_brand_search'
            });
            var itemSearchFilter = search.createFilter({
                name:'custitem30',
                operator:search.Operator.ANYOF,
                values:brand_id
            });
            var filtersArray = [itemSearchFilter];
            itemSearch.filters = filtersArray;
            itemSearch.save();
        }
    }
}

After this script is executed,the filters of the saved search is right.SuiteScript 2.0 saved Search

What can I do to make the SuiteScript 1.0 saved Search same as the SuiteScript 2.0 saved Search?

By the way,nlapiRefreshLineItems is the api of suitescript 1.0,but there is no equivalent in version 2.0.If I want refresh item only in suitescript 2.0,how to do it?

Upvotes: 0

Views: 1306

Answers (2)

felipechang
felipechang

Reputation: 924

Why not?

  1. Load the search
  2. Get the type/columns/filters
  3. Modify the filters
  4. Create another search
  5. Use the previous config

That should work.

Upvotes: 0

nyy
nyy

Reputation: 72

In the 1.0 code change setFilters() to addFilters() so your code should be:

function clientFieldChanged(type, name, linenum) {
    if (name == 'class') {
        var brand_id = nlapiGetFieldValue('class');
        if (brand_id) {
            console.log(brand_id);
            var itemSearch = nlapiLoadSearch(null,'customsearch_item_brand_search');
            var itemSearchFilter = new nlobjSearchFilter('custitem30', null, 'anyof',brand_id);
            var filters = [itemSearchFilter];
            itemSearch.addFilters(filters);
            itemSearch.saveSearch();
        }
    }
}

This works for me, while the setFilters threw an error.

Upvotes: 1

Related Questions