Here is another interesting use case where you could use Jsoup + variablesInResult
parameter of the /start
process-definition endpoint to provide a validations workflow.
Example: you submit a form, and you need to have server side validations with other systems.
Could also be 4 sequential scripts. The performance was the same.
So your setup would look something like:
The function.js looks like this:
if (execution.hasVariable('valueToValidate')){
var valueToValidate = execution.getVariable('valueToValidate')
} else {
throw 'valueToValidate variable does not exist'
}
with (new JavaImporter(org.jsoup))
{
var doc = Jsoup.connect('http://ip.jsontest.com')
.method(Java.type('org.jsoup.Connection.Method').GET)
.header('Accept', 'application/json')
.data('filterABC', valueToValidate)
.timeout(5000)
.ignoreContentType(true)
.execute()
var resBody = doc.body()
}
function spinify(body)
{
var parsed = JSON.parse(body)
var stringified = JSON.stringify(parsed)
var spin = S(stringified)
return spin
}
execution.setVariable('response', spinify(resBody))
// execution.setVariable('response', resBody)
The performance was about the same for returning a SPIN json object vs a string.