hi, i am trying to convert my saved search result ...
# suitescript
r
hi, i am trying to convert my saved search result which is in json to xml with a function but it is not working in netsuite. although it is working in console and giving me output, script version 2.1 - suitelet is there a another way, i just want to convert my search result to xml format
when i debug run and pass searchresult in my function i get join, functions (marshall, settype,_gettype, much more...) all the search things, join, NONE but my searchresult is an array, why ami getting functions inside?? var searchResult = projectSearch.run().getRange({         start: 0,         end: 50       }); var xmlResult = json2xml(searchResult);
n
Looks like you are working with search results directly, each result is a "search result" Object. You will want to parse your results into JSON or in your case probably directly to XML. You could convert to JSON easily enough with array.map(); Alternatively use n/query which can, as a result set, return mapped results.
b
netsuite's debugger and loggers do not actually allow you to inspect actual search results, it allows you to inspect the output of the object's .toJSON method
💯 1
do not rely on the debugger or logs to learn the properties of a NetSuite object
r
@battk but i am getting the function in XML , i am suppose to get the values but instead i get <getValue> <_setType> in my document
b
for (var m in v) {
means that your code goes through the keys of your search results
r
@NElliott can you suggest a example please? i have not used n/query module .. i guess i can try parsing but i dont see much difference
@battk yes exactly..
is there a way i can get values instead on those functions?
b
the keys of your search results will match the keys of a Result Object Members
there will be no values key on your search result, because a Search.Result object has no values key
its json representation does, but thats not what your code is running on
s
NFT makes it easy to turn a search into an array of objects ( legally )