best way to do is it lookup
# suitescript
i
best way to do is it lookup
b
Last time I tested search was significantly faster than lookup. Did that change or why is lookup better than search?
i
what's the code snippet?
c
a lookup is less governance than a search thats about the only reason.... it SHOULD be faster since you have the exact data you're after but its NetSuite so could go either way.
😁 1
b
the code for nlapiLookupField should tell you that they are probably very similar in performance
Copy code
function nlapiLookupField(type, id, columns, text) {
  nsapiCheckArgs(
    [type, id, columns],
    ["type", "id", "columns"],
    "nlapiLookupField"
  );
  nsapiCheckType(type, "nlapiLookupField");

  var searchcolumns = new Array();
  if (isArray(columns)) {
    for (var i = 0; i < columns.length; i++) {
      var column = columns[i];
      if (column.toLowerCase() != "recordtype") {
        var name =
          column.indexOf(".") != -1
            ? column.substring(column.indexOf(".") + 1)
            : column;
        var join =
          column.indexOf(".") != -1
            ? column.substring(0, column.indexOf("."))
            : null;
        searchcolumns[searchcolumns.length] = new nlobjSearchColumn(name, join);
      }
    }
  } else if (columns.toLowerCase() != "recordtype") {
    var name =
      columns.indexOf(".") != -1
        ? columns.substring(columns.indexOf(".") + 1)
        : columns;
    var join =
      columns.indexOf(".") != -1
        ? columns.substring(0, columns.indexOf("."))
        : null;
    searchcolumns[0] = new nlobjSearchColumn(name, join);
  }

  var result = nlapiSearchRecord(
    type,
    null,
    new nlobjSearchFilter("internalid", null, "anyof", id),
    searchcolumns
  );
  var results = null;
  if (result != null && result.length > 0) {
    results = new Object();
    if (isArray(columns)) {
      for (var i = 0; i < columns.length; i++) {
        var name =
          columns[i].indexOf(".") != -1
            ? columns[i].substring(columns[i].indexOf(".") + 1)
            : columns[i];
        var join =
          columns[i].indexOf(".") != -1
            ? columns[i].substring(0, columns[i].indexOf("."))
            : null;
        results[columns[i]] =
          name.toLowerCase() == "recordtype"
            ? result[0].getRecordType()
            : text
            ? result[0].getText(name, join)
            : result[0].getValue(name, join);
      }
    } else {
      var name =
        columns.indexOf(".") != -1
          ? columns.substring(columns.indexOf(".") + 1)
          : columns;
      var join =
        columns.indexOf(".") != -1
          ? columns.substring(0, columns.indexOf("."))
          : null;
      results =
        name.toLowerCase() == "recordtype"
          ? result[0].getRecordType()
          : text
          ? result[0].getText(name, join)
          : result[0].getValue(name, join);
    }
  }
  return results;
}
p
If possible just do the field sourcing.
b
I just tested again, lookup is slower. I did 40 loops to compare. Lookup is around 15% slower than doing search on average, at least in 1.0
b
in 1.0, nlapiLookupField uses nlapiSearchRecord internally
so most of the time it should be slower, simply because it does other stuff that a search wouldnt
it wont be slower in a way that really matters