netsuite - ** SuiteScript 2.0 ** Error while creating search object in client script -


searchresultset.columns.length --> undefined....

what missing in code ?


function pageinit(scriptcontext) {

    try{       var currentrecord = scriptcontext.currentrecord;     var searchobj = search.load({        id:'customsearchvc_bt_duplicate_vendor_list'     });      var searchresultset=searchobj.run();     var noofdupvendors = searchresultset.length;        log.debug({details: "there "+searchresultset.columns.length+" duplicate vendors"});      currentrecord.settext({         fieldid: 'custrecordvc_merge_vendor_total_unique_v',         text: noofdupvendors     });      }catch(e){         log.error("error @ getinputdata stage","error detail :"+e.message);     } 

there no length property on searchresultset object. set doesn't actually contain results(i know, it's weird) need iterate through results total them. in case, may able away sloppy "it'll less 1000" solution:

var searchresults = searchresultset.getresults({     start: 0,      end: 1000 });  var noofdupvendors = searchresults.length 

a solution infinite results this: (untested):

var searchresults; var noofdupvendors = 0;  do{     searchresults = searchresultset.getresults({         start: noofdupvendors,         end: noofdupvendors+1000     });     noofdupvendors += searchresults.length }while(searchresults.length == 1000); 

another (also untested) compact way, if can count on 4000 or fewer results be:

var noofdupvendors = 0;  searchresultset.each(function(result){noofdupvendors++; return true;}) 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -