简体   繁体   中英

How to get Sales Order 'shipaddresslist' value from Transaction Saved Search/Suitescript Search?

In Netsuite, the Sales Order record type contains a field called " shipaddresslist " which contains the Customer Address Internal ID associated with the selected Customer Address.

Unfortunately, there is no search column for Sales Orders that will get the value of " shipaddresslist ," so I had to find a workaround.

Using SuiteScript, I've been able to get the value of this field by looping through my search results, passing in the Sales Order ID to the record.Load() function, and calling record.getValue() on the loaded record, as shown below

Search:

 var salesorderSearchObj = search.create({
   type: "salesorder",
   filters:
   [
      ["type","anyof","SalesOrd"],
      "AND",
      ["item.isfulfillable","is","T"],
      "AND",
      ["status","anyof","SalesOrd:B","SalesOrd:E","SalesOrd:D"],
      "AND",
      ["quantitycommitted","greaterthanorequalto","1"],
      "AND",
      ["location","anyof","1","3"],
      "AND",
      ["mainline","is","F"],
      "AND",
      ["item.type","anyof","InvtPart"]
   ],
   columns:
   [
      search.createColumn({
         name: "transactionnumber",
         sort: search.Sort.ASC,
         label: "Transaction Number"
      }),
      search.createColumn({name: "entity", label: "Name"}),
      search.createColumn({
         name: "custcol8",
         sort: search.Sort.ASC,
         label: "JANコード"
      }),
      search.createColumn({name: "quantityuom", label: "Quantity in Transaction Units"}),
      search.createColumn({name: "statusref", label: "Status"}),
      search.createColumn({
         name: "quantityonhand",
         join: "item",
         label: "On Hand"
      }),
      search.createColumn({
         name: "isfulfillable",
         join: "item",
         label: "Can be Fulfilled"
      }),
      search.createColumn({name: "department", label: "Department"}),
      search.createColumn({name: "otherrefnum", label: "PO/Cheque Number"}),
   ]
});

Loop and Record Loading:

var matches = [];

salesorderSearchObj.run().each(function(result){
  var objRecord = record.load({
      type: record.Type.SALES_ORDER,
      id: result.id,
      isDynamic: true,
  });
  var push = resultToObject(result);
  push.addressid = objRecord.getValue({fieldId:'shipaddresslist'});
  log.debug("Result:",push);
  matches.push(push);
  return true;
});

This works great... Except for the fact that I'm returning around 1000 Sales Orders with the search, meaning that the record.Load() eats through my governance units before I can complete the search and build the entire list of results.

In short, is there a way to return the value of " shipaddresslist " from a Sales Order record directly from the search object? Or perhaps a way to dynamically grab that field without having to load the entire record object?

Any help is greatly appreciated!

SOLVED (KINDA)

Hey all, I asked around and got a semi-solution so in case anyone else comes across this problem, here is a solution.

For my purposes, I was only using SuiteScript because I didn't think you could get the field in Netsuite itself, but I was proved wrong. Here's how to get the field in Netsuite:

Solution

1: Navigate to Lists> Search> Saved Searches> New

2: Select Transaction

3: Under the Criteria tab, Standard subtab, add the following filters:

---Select the Type: Select type of transaction you want to pull up

---Shipping address: Is not empty

---Main Line is True

---Formula (Text): DECODE({shipaddress}, {customer.address},'1','0') Starts with 1

4: Under the Results tab add the following columns:

---Shipping Address

---Customer/project fields is Address Internal id

5: Name the search and hit Save & Run.

The only required criteria is the Formula, but this solution is copy and pasted from SuiteAnswers. I recommend just using the Formula and adding in criteria needed as you see fit.

Credit goes to u/seekcant on the r/Netsuite subreddit for finding and posting this solution.

If you are looking for Internal ID of the customer address, you can add this to the search columns

search.createColumn({
         name: "internalid",
         join: "shippingAddress",
         label: "Internal ID"
      })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM