Have a question for Suitelet experts. Is this the ...
# suitescript
s
Have a question for Suitelet experts. Is this the best way to do it: Assign functions this way -> 1) For UI creation 2) For running the search and assigning the result to an aray 3) Call function # 2 inside # 1 and reiterate over the array returned by function # 2 to populate the list. Reason is I want # 2 to be reusable.
j
I would pass the array as a parameter to function #1, that way you can test with static values or swap out implementations.
Copy code
function getItemList() {
  // returns array
}
function createForm(title, itemList) {
  // returns form
}
function onRequest(request, response) {
  // ..
  var form = createForm('hello', getItemList());
  response.writePage({ pageObject: form });
}
s
the best way to run a search and assign the result to a sane javascript object array is https://github.com/ExploreConsulting/netsuite-fasttrack-toolkit#lazy-search-and-iterate-over-results
j
Does nft do anything about list/record fields having the dubmest shape if you use
search.lookupFields
Copy code
const results = search.lookupFields({
	type: search.Type.SALES_ORDER,
	id: String(salesorderId),
	columns: 'entity'
});
// netsuite returns values of a crazy shape when looking up list/record fields
if (results && Array.isArray(results.entity) && results.entity.length > 0) {
	customerId = results.entity[0].value;
}
s
no, we rarely use lookupFields() instead opting for normal searches in most cases. That said, I am about to add a sane-shape converter for SS2.0 search results.. The link above is for SS1.0 and works like a charm (e.g. if you see the example, and know a bit about functional programming it's a big improvement over 'typical' suitescript code)