This topic contains 3 replies, has 0 voices, and was last updated by eschultz0 8 years, 3 months ago.
-
AuthorPosts
-
August 4, 2016 at 3:07 pm #6262
danstegI am looking to find out how to get the values columns that exist in an array. My my end goal is to iterate through all saved searches in NetSuite and dump the column values into a custom record that I can then search for values within. (getting rid of a custom record and wondering if any saved searches rely on the custom record)
I am able to only get so far, the values that are written back to the custom record appear as “[object Object],[object Object]”… How do I extract the “name” value for each object in the array, for example?
In the console, I can simply branch out the tree to do this, so I’m hoping there is an easier way to do so within Javascript. mySearch.getColumns().getValueOf(“Name”)…somethi ng like that.
Code:
var filters = new Array();
filters.push(new nlobjSearchFilter(‘custrecord_ss_filters’, null, ‘isempty’));var columns = new Array();
columns.push(new nlobjSearchColumn(‘custrecord_ss_type’));
columns.push(new nlobjSearchColumn(‘custrecord_ss_id’));
columns.push(new nlobjSearchColumn(‘internalid’));var searchResults = nlapiSearchRecord(‘customrecord484’, null, filters, columns);
console.log(searchResults.length + ‘ records.’);for (var i=0; i This is a cached copy. Click here to see the original post.
-
August 4, 2016 at 3:37 pm #6263
david.smithCode:
var cols = rec.getAllColumns();
for(var c=0; c<cols.length; c++){
var searchCol = cols[c].getName();
dansteg replied on 08/04/2016, 08:38 PM: Thanks! Was not aware of .getName() .getFormula() or any of the others. I appreciate it. This helps me a ton!
-
August 11, 2016 at 10:34 am #6264
eschultz0I like to do this little trick to convert the results into json objects
Code:
for (var i=0; i < searchResults.length; i++) {
var dataObj = JSON.parse(JSON.stringify(searchResults[i]));// Now you can Access fields as JSON object values
// Example: dataObj.internalId.internalid or dataObj.internalid.name
}
egrubaugh replied on 08/11/2016, 11:31 AM: Never thought of doing this as I never took huge issue with the `getValue` syntax, but I like this. Is there a reason you don’t just parse(stringify) the entire result set at once, rather than doing it on each result individually?
-
August 12, 2016 at 7:34 am #6265
eschultz0However there is a disclaimer to this approach. If the results have two fields of same name such as internalid, only the last field called in the nlobjseachcolumn will be available. at which point using getValue or getText is required to specify. But if each column in your search in unique, this works nicely.
-
AuthorPosts
You must be logged in to reply to this topic.