Hi everyone I am using search.load function to ret...
# suitescript
a
Hi everyone I am using search.load function to retrive saved search results , saved search has 1 filter applied , the issue is that sometimes filters are empty when i log the search object while sometimes search is loaded with filters , Search Obj without filters {"type":"account","id":321,"filters":[],"columns":[{"name":"name","label":"Name","type":"text","sortdir":"ASC"},{"name":"displayname","label":"Display Name","type":"text","sortdir":"NONE"},{"name":"type","label":"Account Type","type":"select","sortdir":"NONE"},{"name":"description","label":"Description","type":"text","sortdir":"NONE"},{"name":"balance","label":"Balance","type":"currency","sortdir":"NONE"},{"name":"internalid","label":"Internal ID","type":"select","sortdir":"NONE"}],"settings":[],"title":null,"scriptId":"customsearch321","isPublic":true} Search Obj with filters {"type":"account","id":321,"filters":[{"name":"name","operator":"startswith","values":["A"],"isor":false,"isnot":false,"leftparens":0,"rightparens":0}],"columns":[{"name":"internalid","label":"Internal ID","type":"select","sortdir":"NONE"},{"name":"name","label":"Name","type":"text","sortdir":"ASC"},{"name":"displayname","label":"Display Name","type":"text","sortdir":"NONE"},{"name":"type","label":"Account Type","type":"select","sortdir":"NONE"}, {"name":"description","label":"Description","type":"text","sortdir":"NONE"},{"name":"balance","label":"Balance","type":"currency","sortdir":"NONE"}],"settings":[],"title":null,"scriptId":"customsearch321","isPublic":true} Script /**  * @NApiVersion 2.x  * @NScriptType Restlet  */ define([     'N/search','N/file','N/url' ], function(search, file,url) {          function get() {         try         {                          var fileContent='';                          var savedSearch = search.load({                 id: 'customsearch321'             });      log.debug('saved search object ',savedSearch);             savedSearchResults=savedSearch.run().getRange(0,1000);                  log.debug('saved search results count',savedSearchResults.length);                  fileContent+="Internal Id,Name,Display Name,Account Type,Description,Balance\n";                  for(var j=0;j<savedSearchResults.length;j++)             {                      fileContent+=savedSearchResults[j].getValue('internalid')+','+savedSearchResults[j].getValue('name')+','+savedSearchResults[j].getValue('displayname')+','+savedSearchResults[j].getValue('type')+','+savedSearchResults[j].getValue('description')+','+savedSearchResults[j].getValue('balance')+"\n";             }                  var csvFile = file.create({                 name: 'searchResults.csv',                 fileType: file.Type.CSV,                 contents: fileContent,                 description: 'csv file',                 encoding: file.Encoding.UTF8,                 folder: -15,                 isOnline: true             });                          csvFileId=csvFile.save();                            var csvFileloaded = file.load({                 id: csvFileId             });                  var hostURL = url.resolveDomain({                 hostType: url.HostType.APPLICATION             });             fileURL="https://"+hostURL+csvFileloaded.url;                  log.debug('File URL ',fileURL);                            return {                 'file_url':fileURL             };               }         catch(e)         {             return {                 'error':e             };         }              }                  return {         'get': get     };     });
@battk any idea sir ?
e
Just a note, the
N/task
module has a method to do this.
a
Hi @ehcanadian thanks for response sir, which method are you referring to ? will it resolve this issue that i am facing currently ?
I want to load a saved search but i dont know why sometimes filters are loaded and sometime search is loaded without filter
e
task.SearchTask, it will save search results to a csv file in the cabinet
not sure about the filters not being loaded
a
Thanks @ehcanadian for help. 👍
b
id guess different users/roles would be the only thing that would give you different results