Logging Set Data in NetSuite: How to Convert Sets to Arrays

In NetSuite, logging a Set directly is not possible, as Set objects are not natively serializable when using log.debug(), log.audit(), or log.error(). Attempting to log a Set will result in an empty or unreadable output.

To properly log a Set, convert it into an array using the spread operator ([...]) or Array.from() before logging it.

Example 1: Using Spread Operator

var mySet = new Set(["apple", "banana", "cherry"]);
log.debug("Converted Set", [...mySet]);

Example 2: Using Array.from()

var mySet = new Set([1, 2, 3, 4]);
log.debug("Converted Set", Array.from(mySet));

Why This Works?

  • Set objects store unique values, but they don’t have a direct string representation.
  • Converting them to an array makes them readable in logs.
  • This approach ensures you can inspect and debug Set data effectively in NetSuite scripts.

Leave a comment

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