[+]
[+]
[+]
[-]
  
  
 [+]
 [+]
 [+]
  
  
  
 [+]
 [+]
 [-]
   
   
   
   
   
   
   
   
   
 [+]
 [+]
 [+]
 [+]
  
 [+]
  
Updated on 8/14/2019
Workflow Documentation
Web Action Script Example
Direct link to topic in this publication:

PREVIOUS  |  NEXT

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 
response.setContentType("application/json")  
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
currentCase.setStatus(s); 

resp.update(currentCase); 

def returnStatus = "{ \"Status\" : \"" 
returnStatus = returnStatus + "OK\"" 
returnStatus = returnStatus + " }" 
 
// sends successful response to the external application
response.writer.write(groovy.json.JsonOutput.toJson(returnStatus)); 
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: { 
 cases=[ 
   { 
     case_key=RMA-A-123
   }
 ] 
}


The URL that calls the Web Action must be received in the following format:
https://{installation_URL}/wpm/mt/{tenant_name}/{data_format}/{script_name}?username={username}&password={password}


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

https://sandbox.webcomserver.com/wpm/mt/webcom_open_issues/json/change_status_to_step_5?username=admin&password=123456789


The URL contains:

  • Installation URLsandbox.webcomserver.com
  • 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