Parameters
Parameters are variables used in datasources and events to obtain specific information from elements within the form.
These parameters are located at the top when creating or editing a datasource or event. They appear as a set of buttons that, when pressed, insert @parameter_name into the code line in the tab. When executing the datasource or event, this value will be replaced with the required data, allowing for greater flexibility and adaptability in retrieving information within the form.
Parameter Explanation
@cuestionarioId
- Description: Form identifier.
- Usage:
@cuestionarioId
@respuesta(X)
- Description: Response from a field in the form instance.
- Usage:
@respuesta(X)
, where X is the field ID. Example:@respuesta(12)
@businessKey.
- Description: Values sent to the Pragmatic Runtime instance from the web page using the forms.
- Usage: Accessed via
@businessKey
. Example:@businessKey.id
@parameter.
- Description: Input parameter received if the datasource is executed from another datasource or event using the @ejecutarDS parameter.
- Usage:
@parameter
. Example:@parameter(12)
@cuestionario.cabezal.
- Description: Access a value from the form header.
- Example:
@cuestionario.cabezal.fechaInicio
@cuestionario.datosIniciales.
- Description: Access a value from the initial data added to the form.
- Example:
@cuestionario.datosIniciales.fechaInicio
@seguridad.
- Description: Access a value from security variables.
- Example:
@seguridad.token
@variablesAmbiente.
- Description: Access a value from environment variables.
- Example:
@variablesAmbiente.endpoint
@accionCustom
- Description: Access the key of the custom action triggered to execute the event.
@instanciaCuestionarioId
- Description: Retrieve the form instance ID.
@respuestas
- Description: Access the array of objects containing the form instance responses.
@preguntas
- Description: Access the array of objects containing the defined fields in the form instance.
@respuestaArray(X, value)
- Description: Validates whether field X contains the value, returning a boolean.
- Usage:
@respuestaArray(X, value)
, where:X
is the field ID.value
is the expected response value.
Example:
Suppose we have a field named ‘Age’ with ID 2
, and the response value is 30
.
If we execute the parameter as follows:
const hasAge30 = @respuestaArray(2, 30) // The result will be true
const hasAge25 = @respuestaArray(2, 25) // The result will be false
@respuestaGrilla(X, column, condition, value)
- Description: Returns the response of a grid field from the form instance.
- Usage:
@respuestaGrilla(X, column, condition, value)
, where:X
: is the ID of the grid field.column
: is the column identifier.condition
: is the condition value used to retrieve the response. This is used to find the row from which to get the response.value
: is the column identifier whose value is retrieved if the condition is met.
Example:
Let’s suppose we have a grid with two columns:
Name | Age |
---|---|
Juan | 30 |
María | 25 |
Executing the following:
const age = @respuestaGrilla(1, 'Nombre', 'María', 'Edad')
The result will be 25
. This happens because it searches for the row where the Name
column is equal to 'María'
, and retrieves the value of the Age
column for that row.
@ejecutarOpcion(‘X’)
- Description: Returns the option values of an option set defined in the platform.
- Usage:
@ejecutarOpcion('X')
, where ‘X’ is the name of the option set.
@accion
- Description: Returns the name of the action sent when executing an event or a datasource.
@respuestaValor
- Description: Defined only when executed on a field-level event. Returns the response value of the selected field.
@respuestaId
- Description: Defined only when executed on a field-level event. Returns the response ID of the selected field.
Example of Use
Data Submission Event to Server
The following JavaScript code performs a PUT request to an endpoint using the Axios instance provided by the tool.
const instanciaCuestionarioId = @instanciaCuestionarioId;
const endpoint = `${@variablesAmbiente.endpoint}/enviarRespuesta/${instanciaCuestionarioId}`;
const queryParams = { username: @seguridad.userId };
const headers = { Authorization: `Bearer ${@seguridad.token}` };
const body = {"questions": @preguntas(), "answers": @respuestas()}
return axios
.post(endpoint, body, { params: queryParams, headers: headers })
.then((response) => {
console.log("Data sent successfully");
})
.catch((error) => {
console.log("Error sending data", error);
});
The JavaScript code carries out the following steps:
Retrieve
instanciaCuestionarioId
: Extracts the unique identifier for the questionnaire instance.Construct the API endpoint: Builds the request URL by appending
instanciaCuestionarioId
to the base endpoint URL.Define query parameters and headers:
- Query parameters (
queryParams
): Containsusername
, which is obtained from@seguridad.userId
. - Headers (
headers
): Includes anAuthorization
header that carries the Bearer token retrieved from@seguridad.token
.
- Query parameters (
Prepare the request body:
- The request payload (
body
) is a JSON object that includes:"questions"
: Retrieves the defined question fields using@preguntas()
."answers"
: Captures the responses using@respuestas()
.
- The request payload (
Execute the API request using Axios:
- Sends a
POST
request to the constructedendpoint
, including:- The request
body
. - The
queryParams
as URL parameters. - The
headers
for authentication.
- The request
- Sends a
Handle the server response:
- If the request succeeds, logs
"Data sent successfully"
to the console. - If an error occurs, logs
"Error sending data"
along with the error details.
- If the request succeeds, logs
Parameters Used:
@instanciaCuestionarioId
→ Identifier for the questionnaire instance.@variablesAmbiente.endpoint
→ Base API endpoint URL.@seguridad.userId
→ Authenticated user’s ID.@seguridad.token
→ Authentication token for secure access.@preguntas()
→ Retrieves the structured list of questions.@respuestas()
→ Fetches the corresponding answers.