Updating Object Values Without Changing the Original in NetSuite JavaScript

In JavaScript, when you assign an object to a new variable, it creates a reference, not a copy. Any changes made to the new variable will also affect the original object. To avoid this, use the spread operator { …object } to create a separate copy. For example: let fields = { custrecord_project_status: 23, charityStatus:… Continue reading Updating Object Values Without Changing the Original in NetSuite JavaScript

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… Continue reading Use of ‘decodeURIComponent’ in NetSuite

Use of ‘encodeURIComponent’ in script

In NetSuite, the ‘encodeURIComponent’ function is useful for encoding URL parameters to prevent errors caused by special characters. It is commonly used in SuiteScript when constructing URLs for redirects or API calls. For example: The Encoded value of the given data is given below, { relatedProjects: [ “2709” ], fields: { custrecord_project_status: 10, custrecord_project_parent_charity_status: “10”… Continue reading Use of ‘encodeURIComponent’ in script

Formatting Date Objects into Structured Components

The splitDate function takes a JavaScript Date object and returns a structured representation containing day, month, and year in both single and two-digit formats. It first verifies if the input is a valid date using dateLogic.isInstanceOfDate(dateObj), ensuring robustness. This approach simplifies date handling in applications, making it easier to work with formatted date values. /**… Continue reading Formatting Date Objects into Structured Components

Extracting URL Parameters in JavaScript

The getParameterByName function retrieves the value of a specified query parameter from a given URL, ensuring special characters are properly escaped and decoded. This helps developers easily access and manipulate URL parameters in web applications, improving dynamic content handling. function getParameterByName(name, url) {             if (!url)        … Continue reading Extracting URL Parameters in JavaScript

Efficiently Classifying Emails for Bulk Sending

The classifyEmails function determines whether to split a set of email recipients into smaller chunks based on a predefined EMAIL_THRESHOLD. If the total count of recipients, CC, and BCC exceeds the threshold, it distributes the recipient list into smaller groups using splitToGroups, ensuring compliance with email limitations. This approach helps manage bulk email sending efficiently… Continue reading Efficiently Classifying Emails for Bulk Sending

Assigning Default Values in JavaScript

The assignDefaultValue function ensures that a variable always has a meaningful value by checking if value meets a certain condition using checkForParameter(value). If the condition is met, it returns value; otherwise, it assigns defaultValue as a fallback. This approach helps prevent errors and improves code reliability by handling missing or undefined values efficiently. var assignDefaultValue… Continue reading Assigning Default Values in JavaScript

The function to check whether a value exists in parameter

To check whether a value exists in parameter: function checkForParameter(parameter, parameterName) {             if (parameter !== “” && parameter !== null && parameter !== undefined && parameter !== false && parameter !== “null” && parameter !== “undefined” && parameter !== ” “ && parameter !== ‘false’) {      … Continue reading The function to check whether a value exists in parameter

Remove duplicates from an array

The expression […new Set(recordIdArray)] in JavaScript provides a simple and efficient way to remove duplicates from an array. The Set object inherently stores only unique values, so when you passrecordIdArray to new Set(), all duplicate elements are automatically filtered out. The spread operator … then converts the set back into a regular array, preserving the… Continue reading Remove duplicates from an array