Use of ‘decodeURIComponent’ in NetSuite

In NetSuite, the ‘decodeURIComponent' function is used to decode URL-encoded parameters, converting them back to their original format. This is useful when retrieving query string values in SuiteScript that were previously encoded using encodeURIComponent.

For example: The decoded value of the given encripted data is given below,

Encrypted data or Encoded data: %7B%22relatedProjects%22%3A%5B%222709%22%5D%2C%22fields%22%3A%7B%22custrecord_project_status%22%3A10%2C%22custrecord_project_parent_charity_status%22%3A%2210%22%7D%2C%22newCharityStatus%22%3A%2210%22%2C%22PROJECT_COMPLETED%22%3A6%2C%22INELIGIBLE_CHARITY_STATUS%22%3A%5B9%2C7%2C8%2C12%5D%2C%22SUSPENDED%22%3A%5B10%5D%7D

Decrypted data or Decoded data:

{
   relatedProjects: [ "2709" ],
   fields: {
      custrecord_project_status: 10,
      custrecord_project_parent_charity_status: "10"
   },
   newCharityStatus: "10",
   PROJECT_COMPLETED: 6,
   INELIGIBLE_CHARITY_STATUS: [ 9, 7, 8, 12 ],
   SUSPENDED: [ 10 ]
}

Using decodeURIComponent ensures that special characters like spaces and & are correctly interpreted when processing URL parameters in NetSuite scripts.

Leave a comment

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