0
votes

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

1
What are the Columns you've set up in this Saved Search? - erictgrubaugh
Account, department, amount and some other including custom segments, custom body fields - user2626026
today I am able to debug my script in Netsuite debugger and found some more details on error, now error says: UNEXPECTED_ERROR 8/17/2017 21:54:25.887 ReferenceError: "nlapiLoadSearch" is not defined. (adhoc$-1$debugger.user#26). sorry for my above comment. error comes only with SuiteScript 2.0, in SuiteScript 1.0 it works. - user2626026
one more thing, my script type is Restlet - user2626026
I have a whole series of videos on transitioning from SuiteScript 1.0 to 2.0 here: youtube.com/playlist?list=PLG2tK6Va2WUDhhcdhklK7wsqmVN-oNF-P - erictgrubaugh

1 Answers

1
votes

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;

}