0
votes

I am new to SuiteScript and I can't seem to fully understand adding url parameters on redirects. I know that the SuiteScript 1.0 documentation states that extra parameters can be added according to this function:

sendRedirect(type, identifier, id, editmode, parameters)

type {string} [required] - The base type for this resource

identifier {string} [required] - The primary id for this resource (record type ID for RECORD, scriptId for SUITELET, taskId for tasklink, url for EXTERNAL)

id {string} [optional] - The secondary id for this resource (record type ID for RECORD, deploymentId for SUITELET)

editmode {boolean true || false} [optional] - For RECORD calls, this determines whether to return a URL for the record in edit mode or view mode. If set to true, returns the URL to an existing record in edit mode, otherwise the record is returned in view mode.

parameters {hashtable} [optional] - An associative array of additional URL parameters as name/value pairs

But I am really confused on the last fourth parameter where the documentation states that an associative array is needed. I have tried writing this code to test adding that parameter.

function suitelet(request, response) {
    var arrayParam = [];
    arrayParam.push({custparam_key: 'value'});
    response.sendRedirect('SUITELET', 'customscript_a', 'customdeploy_a', 
    arrayParam);
}

But I am unable to track down where that last parameter is located in my Suitelet. The above code does allow the user to redirect back to the same form itself with additional default parameters. But I don't want the same default parameters. I want to be able to make additional custom parameters on certain conditions where I need to redirect the user.

I hope that all made sense. I feel like maybe I am not understanding what that last parameter is used for. If that is the case, then any clarification would be helpful!

3
did you try passing simple JSON object as parameters to sendRedirect (i.e key-value pair like: { a: 'aa', b: 'bb' })?Avi
I have, but I was unable to capture that parameter after the form is redirected. I am guessing that maybe it did work. Perhaps I just don't know where that parameter goes in the context of GET and POST methods.thomas93

3 Answers

1
votes

Create your associative array like this:

 params['custparam_test1'] = value_test1;

Then just get this:

var param = request.getParameter('custparam_test1')

In your code you have an object in the arrayParam[0], which is the zero position, however it is not an associative array.

1
votes

Your code should be:

function suitelet(request, response) {
    var params = {
      custparam_key: 'value'
    };
    response.sendRedirect('SUITELET', 'customscript_a', 'customdeploy_a', params);
}
0
votes
sendRedirect(type, identifier, id, editmode, parameters)

But you used it as

response.sendRedirect('SUITELET', 'customscript_a', 'customdeploy_a', 
arrayParam);

So if you match it to the parameters on the documentation

Type = Suitelet
identifier = customscript_a
id = customdeploy_a
editmode = arrayParam

You should have called it as

response.sendRedirect('SUITELET', 'customscript_a', 'customdeploy_a', null, arrayParam);