Pass JSON Request Data to Your Script

Use Request data as input from which to run your Script.

Pass Request Data Into Your Script

‌Pass Request-related data into your Script in the following ways:‌

  • Request data: ProcessMaker Platform uses a schema-less JSON data model from which to read, write, and store Request data. Since the JSON data model is schema-less, meaning that it does not require a specific schema or structure from which ProcessMaker Platform assets must conform, the JSON data model is structured from the JSON objects in assets used in a Request, such as the Variable Name setting values in a Screen or variables a Script creates. When an in-progress Request routes through the Process, Request data aggregates into the JSON data model, thereby becoming Request data. Users or group members that have the Requests: Edit Request Data permission may view the JSON data model for a completed Request. This JSON data model displays from the Data tab in a completed Request's summary. Below is an example. Scripts can call Request data by referencing these JSON objects derived from Variable Name setting values in Screens.

  • Script Task element Configuration: Enter JSON data to pass to the Script when configuring the Script task element in Process Modeler. In the example below, the data from JSON Variable Email is being passed to the Script using the Script Configuration panel of a Script Task element. Note that revisions made to Script Config Editor screen do not save until the Close button is clicked.

  • Magic Variables: ProcessMaker Platform uses a set of Magic Variables that become part of the JSON data model for all Requests. ProcessMaker Platform uses these Magic Variables to store user, Process, and Request related data for all Requests. During an in-progress Request, these Magic Variables are updated. All Magic Variables are preceded by an underscore (_) character in the JSON data model. See Reference Magic Variables in ProcessMaker Platform Assets.

  • Environment Variables: The sensitive information that an Environment Variable represents can pass to a Script when it runs. Usage depends on the programming language that the Script uses. In the usage examples below, ENV_VAR_NAME represents the name of the Environment Variable. See Variable Syntax, Usage, and Examples.

Enter Mock Request Data Coming Into Your Script

‌Use the Sample Input panel to mock Request data that comes into your Script to test how the Script runs using Request data you expect.

Define the variables in a Screen when you configure its controls. See information about each control.‌

Permissions

Your user account or group membership must have the following permissions to enter mock Request data into a Script:

  • Scripts: View Scripts

  • Scripts: Create Scripts

  • Scripts: Edit Scripts

See the Scripts permissions or ask your Administrator for assistance.

Follow these guidelines to mock Request data coming into your Script:‌

  1. ​Open the Screen in which to view its JSON data model.

  2. Enter Preview mode on the Screen page to view its JSON data model. Click the Preview button from Screen Builder's top menu to enter Preview mode.

  3. Enter values into the control settings as if you were using the Screen in a Request. In the Data Preview panel, the JSON data model displays the key-value pairs in each object element. The keys' values are those you enter in the Screen preview. Understand what the key names are. Each key is derived from a Screen control's Variable Name setting value. Use these key names as variables in your Script. The Variable Name setting values become part of the Request data and contain the content that Request participants enter into that Screen during a Request. Mock these Variable Name setting values as input data to your Script.

  4. After you have entered values into the Screen in Preview mode, the entire JSON data model displays in the Data Preview panel. Copy the JSON data model.

  5. Paste the JSON data model into the Sample Input panel in Script Editor. If you use any variables as defined in the JSON data model in your Script, Script Editor uses those variable values during script testing.

  6. Optionally, mock the Magic Variables that your Script would reference during an in-progress Request. ProcessMaker Platform uses a set of Magic Variables that become part of the JSON data model for all Requests. ProcessMaker Platform uses these Magic Variables to store user, Process, and Request related data for all Requests. During an in-progress Request, these Magic Variables are updated. All Magic Variables are preceded by an underscore (_) character in the JSON data model. Enter the Magic Variable into the Sample Input panel as part of the JSON data model, and then enter mock values for each. See Magic Variable Descriptions.

  7. Click Run.

  8. In the Output panel, view the mocked Request data.

Enter Other JSON Data as Input to Your Script

‌Use the Configuration panel to include JSON configuration settings your Script uses when it runs. For example, include the Client ID and Client Secret values in JSON format for OAuth 2.0 verification to a third-party service's API your Script must access to access the API. By entering these values into the Configuration panel, you can verify during testing that these values are valid for the third-party service.‌

A Script may reference Screen control values during a Request by placing their Variable Name setting values within quotation marks ("). In the example below, FullName is the Variable Name setting value for a control to store a Request participant's full name:

{
    "Name": "FullName"
}

Last updated

Logo

© 2024 ProcessMaker, Inc. All Rights Reserved. Except as otherwise permitted by ProcessMaker, this publication, or parts thereof, may not be reproduced in any form, by any method, for any purpose.