ServerRequest.parameters
Ensure that parameters are properly validated to avoid cross-site scripting (XSS) injections. Do not use <script> tags in your parameters.
Property Description |
The server request parameters, as name:value pairs. Note that if the server request is a Get request, parameters are sent as part of the URL. If the server request is a Post request, parameters are sent within the request body.
Note:
Parameters cannot be arrays. Use JSON.stringify/JSON.parse instead to handle arrays. |
Type |
Object (read-only) |
Module |
|
Parent Object |
|
Sibling Object Members |
|
Since |
2015.2 |
Errors
Error Code |
Thrown If |
---|---|
|
You attempted to edit this property. This property is read-only. |
Syntax
The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/https Module Script Samples.
// Add additional code
...
// example from a Suitelet
onRequest: function(context) {
// in the following, context.request is an https.ServerRequest (per Suitelet onRequest(params.request) entry point)
if (context.request.method === 'GET') {
// request is coming from a User Event script, for instance, on a form load; parameters are in the URL as name:value pairs (as the query string)
var myName = context.request.parameters.custpage_nameParam; // here, 'custpage_nameParam' and 'custpage_phoneParam' are parameter names set
var myPhone = context.request.parameters.custpage_phoneParam; // by the requesting script and sent in the HTTPS request
}
if (context.request.method === 'POST'){
// request is coming from a Submit button click on the form, submitting the form (using a user event script); parameters are in the form fields
var myName = context.request.parameters.nameFld; // here, 'nameFld' and 'phoneFld' are field ids on the form for the Name and Phone fields
var myPhone = context.request.parameters.phoneFld;
}
}
...
// Add additional code
Code Samples
This script sample uses the define function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript 2.x Global Objects
/**
*@NApiVersion 2.x
*@NScriptType Suitelet
*/
define([], function() {
function onRequest(context) {
var params = context.request.parameters; // {"param1":"value1"}
var param1 = params.param1; // value1
...
// Add additional code
...
}
return {
onRequest: onRequest
};
});