0
votes

I am trying to utilize a Saved Search to generate a csv file. My biggest issue is that I have several columns that are formulas. From looking at the API, I need to use the getValue() function which takes 3 params - name, join, summary. My issue is I do not know the "name" of the formula columns. Via the SuiteScript IDE (Eclipse with Plugin) it showed me a "getAllColumns()" function that should return an array of the columns. I also found it in this documentation: https://system.netsuite.com/app/common/scripting/nlapihandler.nl?downloadapi=T However, when I run the script, I get the error "[L.nlobjSearchResult;" has no public instance field or method named "getAllColumns"."

Below is my code. Any recommendations would be great as to how I can get at the names of all the columns easily, including the formulas. I have 38 columns, so would want to loop through them and not just do a getValue('name1') if possible.

function gen_ven(){
    var data = '';//this will contain all of the eventual data for this file
    var sQF = '"', sDelim = ',';
    var results = nlapiSearchRecord('vendor','customsearch_se_ven');
    var columns = results.getAllColumns();
for(var i =0;i<results.length;i++)
{
        for(var j = 0; j<columns.length; j++){
            data += sQF + results[i].getValue(columns[j])+sQF+sDelim;
    }
    data += '\n';
}


var file = nlapiCreateFile('Vendor.csv', CSV, data);
response.setContentType(file.getType(), 'Vendor.csv');
response.write(file.getValue());
}

I also did try using results.prototype.getAllColumns() but this didn't work at all.

Thank you for any help you can give

2

2 Answers

2
votes

The reason you're getting that error is because getAllColumns() is a member of the nlobjSearchResult object, and nlapiSearchRecord() returns an array of nlobjSearchResult.

To get it to work, just use results[index].getAllColumns().

1
votes

you could use getName() function of the nlobjSearchColumn and get the headers of the saved Search

var start = function(request, response)
{
    var searchId = "667";//a saved search internal id
    var rec = nlapiLoadSearch('customer', searchId);//load that saved search
    var columns = rec.getColumns();//get columns of it
    var output = "";//the data for the csv file
    var delimiter = ",";//delimiter for the csv file
    for(var i in columns)
        {
            output += columns[i].getName() + delimiter ;//use the getname()
        }
    var folderId = '123';
    var file = nlapiCreateFile('My New CSV', 'CSV', output);//save the file
    file.setFolder(folderId);
    nlapiSubmitFile(file);
    response.write("done");
}