0

I have created a saved search for transaction in netsuite and with suitescript 2.0 I am showing saved search data in my application. In application user can apply filter on any fields (please see the attached screenshot). For example user select "Aug 2011" for posting period, only transactions of Aug 2011 should be loaded. This works fine if I create a filter with internalid of "Aug 2011", but on UI I dont have internal id.

sample code:

/*
 here is my required module
*/

function getTransactionData(datain)
{
  try
  {

       var objSearch = search.load
                    ({
                        id: datain.savedsearchid
                    });
          /***** Work *****/
          objSearch.filters.push(search.createFilter({ name: "postingperiod",  operator: "ANYOF", values: "1" })); //here 1 is internalid of periodname "Aug 2011"

          /***** Not Work (SSS_INVALID_SRCH_FILTER_JOIN) *****/
          //objSearch.filters.push(search.createFilter({ name: "postingperiod", join: "accountingperiod",  operator: "ANYOF", values: "Aug 2011" }));

           objSearch.run();
  }
  catch(ex)
  {
      log.error("getTransactionData",  ex);
      throw ex;
  }
}

I tried with join but seeing "SSS_INVALID_SRCH_FILTER_JOIN" error from Netsuite.

Can any one please help me regarding this.

Thanks in advance

user2626026
  • 21
  • 3
  • 8

2 Answers2

2

I edited your code to a more simplified one to understand better. If you get the gist of how it works, you can edit/customize the way you want.

I assume there is join 'accountingperiod' option available for 'postingperiod' and this works perfectly in your saved search you created in netsuite without using suitescript.

/*
 here is my required module
*/

function getTransactionData(datain) {
    try {

        var objSearch = search.load({
            id: datain.savedsearchid
        });
        var defaultFilters = objSearch.filters;
        var customFilters = [];

        //Adding filter
        customFilters = ['postingperiod', 'ANYOF', '1'];
        defaultFilters.push(customFilters);
        customFilters = undefined;
        customFilters = [];



        //Adding filter
        /*
        customFilters = ['postingperiod.accountingperiod', 'ANYOF', 'Aug 2011'];
        defaultFilters.push(customFilters);
        */

        objSearch.filters = defaultFilters;

        var objSearch_run = objSearch.run().getRange({
            start: 0,
            end: 10
        });

    } catch (ex) {
        log.error("getTransactionData", ex);
        throw ex;
    }
}

If you want to know how filters is stored in saved search you created in netsuite, you can use the script debugger. The following code is suitescript 1.0

//Load Saved Search
get();

function get() {
    var search = nlapiLoadSearch('transaction', ' ENTER SAVED SEARCH ID HERE ');
    log.debug('search',search);
    var searchFilters = search.getFilterExpression();
    log.debug('searchFilters',searchFilters);

    return search;
}
Manu AVS
  • 557
  • 3
  • 7
  • thanks @Manu, here "1" is an internalid of periodname "Aug 2011" and that internalid I dont know in my wpf application, that why I wanted to filter transactions based on periodname not based on internalid – user2626026 Dec 13 '17 at 09:44
0

I assume your application is a Suitelet? If so, you need to do a select field type of your record. So probably of 'posting periods'. This will show your periods in a drop down.

When the user selects it, have a client side script auto refresh the data and load your saved search.

Alternatively, you can load all the data and do the filtering client side DOM filtering. Really need a bit more information about your "application".

Lez Yeoh
  • 340
  • 1
  • 2
  • 13
  • my application is .net wpf application, not suitelet. – user2626026 Dec 11 '17 at 10:49
  • Have you tried changing the filter to: objSearch.filters.push(search.createFilter({ name: "postingperiod", join: "accountingperiod", operator: "ANYOF", values: "1" })); – Lez Yeoh Dec 12 '17 at 22:49
  • here "1" is an internalid of periodname "Aug 2011" and that internalid I dont know in my wpf application, that why I wanted to filter transactions based on periodname not based on internalid – user2626026 Dec 13 '17 at 09:40
  • You may need to do two searches. First do a search of all posting periods and get the internal id and names. Then do a filter/match on the internalid you require? – Lez Yeoh Jan 09 '18 at 03:09
  • it seems you are right, I will have to make two search – user2626026 Feb 27 '18 at 05:07