netsuitesuitescript

Get Saved Search values for multiple "formula" columns


Morning Gurus,

I have a saved search within Netsuite with multiple "formula" columns.

For example, there are several formulapercent' named columns, although thelabel' for each is unique.

However when using nlobjSearchResult.getValue('formulapercent') naturally I only get the first formulapercent column value.

How do I specify in getValue which of the formula columns I want to return the value for?

I really don't want to use a column number, in case I need to insert a new column to the saved search within Netsuite later.

Hoping for something along the lines of nlobjSearchResult.getValue('formulapercent','<label>')

I have tried the multi parameter option, but it does not work.

Simple fix?

Cheers

Steve


Solution

  • Thought I'd add an answer I have since learned.

    Instead of generically numbering the columns. For example:

    var column = []
    column[0] = new nlobjSearchColumn('formulanumeric').setFormula('myformula1');
    column[1] = new nlobjSearchColumn('formulanumeric').setFormula('myformula2');
    searchresults = nlapiSearchRecord(.......);
    

    Instead of this, I found the easiest way to retrieve the formula column values was to uniquely define the columns:

    var colformula1 = new nlobjSearchColumn('formulanumeric').setFormula('myformula1');
    var colformula2 = new nlobjSearchColumn('formulanumeric').setFormula('myformula2');
    
    var searchresults = nlapiSearchRecord('item',null,filters,[colformula1,colformula2]);
    

    To then grab the formula results:

    var formulares1 = searchresults[i].getValue(colformula1');
    var formulares2 = searchresults[i].getValue(colformula2');
    

    Removes the issue if column orders change.

    Thought this might help somebody.