Passing parameters from a client script to external suitelet form

If we have to pass parameters from a client script to an external suitelet form, we cannot create an external URL to pass parameters of the suitelet script using urlResolveScript in the client script.

Since the client script is attached to the suitelet script, we can get the URL of the suitelet using the window.location method.href. After receiving the URL, we can replace the parameters and load the form with the required parameters.

Example:

let baseUrl = window.location.href;

                    const urlObj = new URL(baseUrl);

                    urlObj.searchParams.set(’empId’, employeeId);

                    urlObj.searchParams.set(‘status’, status);

                    urlObj.searchParams.set(‘lead’, lead);

                    baseUrl = urlObj.toString();

                    document.location = baseUrl;

(NB: This code is written in client script)

Here I am getting the URL of the current suitelet script in the variable baseUrl, converting it into a URL, and storing it in urlObj. searchParams.set() method allows me to replace a parameter if that parameter is present in the URL or to add the parameter to the URL. Then I convert it into a string and store it in baseUrl. I am using document.location, to redirect the page to the URL created.

Leave a comment

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