As NetSuite developers, it is important that we understand how NetSuite works. One of the most important aspects to understand is URLs. Through the SuiteScript API, we can utilize URLs to pass in custom parameters. By using parameters, we can redirect users to records with custom information which can be utilized by other scripts.

Unfurling the Power of URLs

In a recent SuiteScript article, we discussed how to create dynamic URL record links using the URL module. When compared to the traditional method, this is the safer and more versatile way to retrieve the URLs we need.

const salesOrderUrl = url.resolveRecord({
    recordType: 'salesorder',
    recordId: 106,
    isEditMode: true
});

Of course, we could have created the url manually, like this:

“https://system.netsuite.com/app/accounting/transactions/salesord.nl?id=106”

We could even concatenate the string with other variables:

“https://system.netsuite.com/app/accounting/transactions/salesord.nl?id=” + recId”

But, as mentioned in our previous post, this is not the safest way to handle URLs. Hard-coding values should be a last resort, not a first. Since NetSuite provides this functionality natively with the url.resolveRecord method, we should take advantage of that resource. This will ultimately be safer in the long run in case NetSuite ever modifies the structure of URLs.

Passing Parameters

When discussing the URL module, we also briefly mentioned a special option for the url.resolveRecord method. We can pass in custom parameters into the URL.

const salesOrderUrl = url.resolveRecord({
    recordType: 'salesorder',
    recordId: 106,
    isEditMode: true,
    params: {'success': 'T'} // <-- This here
});

We can pass custom data into the URL whenever the user is redirected to that record. In the parameters option, you will need to pass an object of some kind. Each of those values must be a string, but keep in mind that you would probably want to generate those strings dynamically in your script. We hardcoded some values just for the sake of example.

There are so many possibilities that you could use parameters for. They are helpful when needing to pass a small piece of data between records. URLs do have a limit, however. We would not recommend passing large amounts of data between records through URL parameters. A safe limit for URLs is roughly about 2,000 characters. That’s quite a bit of data you could use, but we’d recommend exploring another path for passing large amounts of data like that. The shorter the better when it comes to URLs.

Handling Parameters

Once the user is directed to the target page, we need to handle those parameters in some way. Once again, there are a myriad possibilities with this versatile tool. We’ll just give one example for illustration.

Sometimes we need to show a message to the user in view mode. Let’s imagine that I passed a parameter into the URL called “success.” If the previous automation was successful, I redirect to the page in view mode and pass the “success=T” parameter into the URL. Then, I check if that parameter exists and is set to true. If so, a message will display showing that the automation was successful.

function beforeLoad(context) {
    if(context.type !== 'view') return;

    if (context.request.parameters['success']) == 'T' {
        context.form.addPageInitMessage({type: message.Type.INFORMATION, message: 'Automation was Successful', duration: 7000});
    }
}

Conclusion

There are many possibilities with parameters. We hope this at least helps point you in the right direction! If you have any questions, let us know in the comment section. And don’t forget to subscribe to our email list if you haven’t already!