Developers » Script Examples by Type » Web Action Script Example


Web Action Script Example

Quick Links

Workflow provides Web Action scripts that enable third-parties to collaborate with Workflow by sending data in JSON or XML formats. We unpack the data received with the Web Action script.

The following example illustrates how an external application can change the status of a case. The application packs the case_key using JSON and the Web Action script unpacks the file and updates the status of a case. To prepare for the request, we first create the Web Action script.

Create Web Action Script

[Back to top]

Create a Web Action type script named change_status_to_step_5  and enter the following code in the code window:

// external application defines format expected by Workflow 
def slurper = new groovy.json.JsonSlurper() 

// gets JSON sent from an external application
def text = request.getBody(); 

// Parse a text representation of a JSON data structure
def json = slurper.parseText(text) 

def responseContent = ""; 

// get case key from parsed JSON
def currentCase = resp.getCase(json.cases[0].case_key); 

// case will end up in this status
def s = resp.getStatus('step_5_edit'); 

// moves case to status step_5_edit


def returnStatus = "{ \"Status\" : \"" 
returnStatus = returnStatus + "OK\"" 
returnStatus = returnStatus + " }" 
// sends successful response to the external application
response.writer.close() ;

Note: If a request fails, Workflow displays a system error. If you want a more specific error message, you can add a try/catch statement to your script.

External Application Code Samples

[Back to top]

The following JSON code sample is sent by the external application:

json: { 

The URL that calls the Web Action must be received in the following format:

In this example, the external application sends the following URL:

The URL contains:

  • Installation
  • Tenant Namewebcom_open_issues
  • File FormatJSON
  • Web Action Script Namechange_status_to_step_5
  • Usernameadmin
  • Password123456789

Note: The username and password should belong to the existing user.

After the URL is generated, the change_status_to_step_5   Web Action script will execute.

Related Articles