user2626026
user2626026

Reputation: 21

Colums name of saved search with suitescript

I am using suite script (API version is 1.0). I have created a Saved search for transaction in netsuite account. Now I want to pull the data from saved search into my database, but before this just want to list the columns present in saved search on my mapping screen.

For this I have written below script:

function GetColumnName()
{
        var s = nlapiLoadSearch('transaction', 'customsearchtestsavedsearchwithcustfield');
        var columns = s.getColumns();
        return columns;
}

but in above code getColumns function is not working and netsuite giving below error (error does not say much)

TITLE
**UNEXPECTED_ERROR**
TYPE
System
DATE & TIME
8/17/2017 4:34 am
DETAILS

Can any one please help me regarding this.

Thanks

Upvotes: 0

Views: 3606

Answers (1)

Todd Grimm
Todd Grimm

Reputation: 544

I believe this will give you the result you are looking for. Just pass in the nlobjSearch object and it will return an array of the Column names. This is verified as functional, if you still receive an error then there is something wrong with the search being loaded and you should diagnose this search in the UI.

function searchColTitles(search) { // search is the nlobjSearch from an nlapiLoadSearch(), or nlapiCreateSearch()

var columns = [];
var c;
var cName;
var columnNames = [];


columns = search.getColumns();

for (c = 0; columns.length && c < columns.length; c += 1) {
    cName = columns[c].label;
    if (!cName) {
        cName = columns[c].name;
    }
    columnNames.push(cName);
}

return columnNames;

}

Upvotes: 1

Related Questions