Chanuka Ranaba
Chanuka Ranaba

Reputation: 635

Suitescript 2.0 get saved search value by column index

I'm using suitescript 2.0. I tried to get the value of that report using the below code. Which I referenced from the suitescript 2.0 documentation

/**
 * @NApiVersion 2.x
 * @NScriptType restlet
 */

define(["N/record", "N/error", "N/search", "N/log", "N/format"], function(
  record,
  error,
  search,
  log,
  format
) {
  return {
    get: getProductionIncome
  };

function getProductionIncome(){


 var mySearch = search.load({
 id: 'customsearch_db_tot_rev'
 });
 var resultSet = mySearch.run();
 var firstResult = resultSet.getRange({
 start: 0,
 end: 10
 })[0];
 // get the value of the second column (zero-based index)
 var value = firstResult.getValue(resultSet.columns[1]); 


return "Amount: " + value;
}
});

I'm getting the following error.

error code: SSS_MISSING_REQD_ARGUMENT error message: {"type":"error.SuiteScriptError","name":"SSS_MISSING_REQD_ARGUMENT","message":"Result.getValue: Missing a required argument: name","stack":["createError(N/error)","getProductionIncome(/SuiteScripts/revenue_sync_script.js:34)","createError(N/error)"],"cause":{"name":"SSS_MISSING_REQD_ARGUMENT","message":"Result.getValue: Missing a required argument: name"},"id":"","notifyOff":false,"userFacing":true}

I have also tried the

var AccType= firstResult.getValue({ name: "type" });

but couldn't get the result because I don't know the exact name.

Upvotes: 0

Views: 2914

Answers (1)

Avi
Avi

Reputation: 2069

error code: SSS_MISSING_REQD_ARGUMENT error message: {"type":"error.SuiteScriptError","name":"SSS_MISSING_REQD_ARGUMENT","message":"Result.getValue: Missing a required argument: name","stack":["createError(N/error)","getProductionIncome(/SuiteScripts/revenue_sync_script.js:34)","createError(N/error)"],"cause":{"name":"SSS_MISSING_REQD_ARGUMENT","message":"Result.getValue: Missing a required argument: name"},"id":"","notifyOff":false,"userFacing":true}

From the error message it seems your search does not contain 2 columns to fetch second column.

Please verify first if your search has 2 columns to being with.

but couldn't get the result because I don't know the exact name.

To get column name, you can use column.name and column.join to get join. For further reading check this out.

Upvotes: 1

Related Questions