This page was last edited on March 3, 2021, at 16:00.
Comments or questions about this documentation? Contact us for support!
Script blocks are great for adding ‘presentation’ logic to your app - comparing values and branching out to different blocks, performing date calculations, combining prompts. It’s possible to invoke RESTful web services directly from a Script block, and this may be sufficient if the services are simple. It is advised not to use the Script block for tasks like handling security certificates, or calling onto databases or SOAP-based web services.
Integration Hub is a simple and powerful way to do this, and brings many other benefits such as support for multiple environments’ endpoints (dev/test/production, for example) and the ability to create automated test scripts. Using Integration Hub is a good way to keep your Intelligent Automation apps and their assorted presentation logic separate from the details of how to call onto your enterprise’s backend systems.
You can use Script blocks to perform complex operations, such as loops and if clauses, and define their own methods.
To add and configure Script blocks in a callflow:
To learn how to use the Script block to add custom rich media, refer to the Rich Media page in this manual.
Click the link below to download a zip file that documents the scripting methods that you can call from the Script block.
//
// Call the Web Service (note that session variables can be included in the URL and we then use context.expandVariables() to replace the variable with whatever is in session at runtime)
//
def iTimeout = 5000;
def sURL = "https://testwebservice.com/[var:WebServiceName]"
sURL = context.expandVariables(sURL);
def dataResult = context.getRemoteHttpData(sURL, "POST", params, iTimeout);
def xml = dataResult.responseXml;
//
// Parse the response
//
assert null != xml.status;
assert "" != xml.status.text();
def sStatus = xml.status.text();
for (variableDeclaration in xml.variables?.variable)
{
def sName = variableDeclaration.@name;
def sValue = variableDeclaration.@value;
context.setVariable(sName, sValue);
}
if ("success" == sStatus)
{
context.log("Found");
return "success";
}
else if ("not found" == sStatus)
{
context.log("Not found");
return "not found";
}
if (context.getVariable(“AuthMethod”) == “AccountNumber”)
{
return “account number”;
}
else
{
return “social security number”;
}
context.setVariable(“AuthMethod”, “AccountNumber”);
def result = callScript();
assert “account number” == result;
context.log(“Passed test”);
To handle different behaviors in case of a recognition failure, you can use a script to split the results based on maxnomatches and maxnoinputs.
if (context.getLastResultDetail().contains("maxnomatches"))
{ return "max retries"
}
else {
return "max timeouts"
}