I am looking for a way to check item types. Some r...
# suitescript
m
I am looking for a way to check item types. Some records have an itemtype field associated with the lines, so you can do something like this:
Copy code
let itemType = invRec.getCurrentSublistValue({
        sublistId: "item",
        fieldId: "itemtype",
      });

      let itemRecordType;
      switch (itemType) {
        case "InvtPart":
          itemRecordType = "inventoryitem";
          break;
        case "NonInvtPart":
          itemRecordType = "noninventoryitem";
          break;
        case "Service":
          itemRecordType = "serviceitem";
          break;
        case "Assembly":
          ...
But if you don't have that, is there another way? Can I rely on search for example? I have the internal ID
b
lookup the recordtype column using a search
or if you only have 1 item, lookupFields
m
@battk You mean from the parent "item" record?
Will it work for all of them?
b
it basically works for most search results that arent using summary columns
m
but what the search type itself should be?
b
an item search
m
got it, thanks a lot
didn't work, I had to do this
Copy code
let srch = search.create({
            type: "item",
            columns: ["type"],
            filters: [["internalid", "is", itemID]],
          });
          let item = srch.run().getRange(0, 1)[0];
          let itemType = item.getValue("type");
          if (itemType != "Service") {
            throw "All line items must be service items for external service requests.";
          }
but I was forgetting about the parent record, thanks for reminding me
b
what did your attempt to use recordType look like?
m
Copy code
let result = srch.run();
let itemType = result.recordType;
returned undefined
b
result is a resultSet
its not a search result
m
I followed the docs
Let me check again
Something is wrong with that code I guess, anyway it works now.