Retrieve only the child subsidiary name from the Subsidiary field using a search.

result.getText({ name: ‘subsidiary’ }).split(‘:’).pop().trim() || “”

result.getText({ name: 'subsidiary' })

  • Retrieves the text representation of the subsidiary field from the search result.
  • In NetSuite, getText is used to fetch the displayed text instead of the internal ID.

.split(':')

  • Splits the retrieved text by the colon (:) separator.
  • Some NetSuite fields (like subsidiary) can return values in the format:
"Parent Subsidiary : Child Subsidiary"
  • So, after splitting, this creates an array like:
["Parent Subsidiary", "Child Subsidiary"]

.pop()

  • Retrieves the last element from the split array.
  • This ensures that if the subsidiary name has a parent-child hierarchy, it only extracts the last part (child subsidiary name in this case).

.trim()

  • Removes any leading or trailing spaces from the extracted text.

|| ""

  • If the result is null, undefined, or an empty string, it defaults to an empty string (""), ensuring there’s no error when handling missing values.

Leave a comment

Your email address will not be published. Required fields are marked *