/
Groovy Variables

Groovy Variables

Groovy variables enable more complex mapping of data. It could be that status or date needs to be mapped to other values.



Available scopes

The groovy script has the following objects / variables available

Variable name

Description

Note

Variable name

Description

Note

issue

the current issue that the call is operating on

 

response

the parent response from the previous runned call as String 

 

jsonSlurper

Use JsonSlurper

Does not work with  Groovy 3.0.7 and OpenJDK 64bit 11.0.13+8 (https://issues.apache.org/jira/browse/GROOVY-9802 )
See workaround below

jsonOutput

Use JsonSlurper

Does not work with  Groovy 3.0.7 and OpenJDK 64bit 11.0.13+8 (https://issues.apache.org/jira/browse/GROOVY-9802 )
See workaround below

scope

all previous defined variables or responses

Example if call A get
name = Peter as json response
then call B that get
the an issue with all its properties

then call C and c wants to access name it can do so by using

scope.name



 

 

Common Error

Exception in your groovy code java.lang.RuntimeException: Unable to load FastStringService

Workaround

Workaround is to use ObjectMapper instead of JSON Slurper

Parse JSON

import com.fasterxml.jackson.databind.ObjectMapper ObjectMapper mapper = new ObjectMapper() //response is passed in from the parent action def myRespnse = mapper.readValue(response, HashMap.class)

Produce JSON

def myList = [] myList.add([email:issue.reporter.emailAddress]) return mapper.writeValueAsString(myList)




See examples

Related content

JSON Path - Pick data from response
JSON Path - Pick data from response
More like this
JSON Path variables
JSON Path variables
Read with this
Auto populate Jira servicedesk organisation from a group
Auto populate Jira servicedesk organisation from a group
More like this
Comment Issue
Read with this
Send SOAP message
Send SOAP message
More like this
Mapping of priority
Mapping of priority
More like this