How to manipulate a JSON file in Automation Anywhere

<< Click to Display Table of Contents >>

Navigation:  Low-code Process Automation > Studio Cloud - Authoring environment > Bizagi Studio > Bots > Automation Anywhere bot integration >

How to manipulate a JSON file in Automation Anywhere

Overview

As explained in Automation Anywhere Metabot, the Bizagi Metabot is used by Automation Anywhere, so that the bot can perform different actions using the OData layer to interact with Bizagi. Within the operations that the Bizagi Metabot can perform, some of them return a JSON with the result of the bot's invocation. This operations are:

GetProcess

GetCasesByProcess

GetWorkitemsByCase

 

If the JSON returned by Automation Anywhere contains one single object (one process, one case, or one workitem), data can be easily processed. However, in scenarios where more than one object is returned, the Bizagi Metabot is not capable of parsing the JSON (e.g. iterate the JSON to obtain the individual results of the invocation). For example, if you want to obtain the information of a case, you first need the process ID. The GetProcess action returns all the processes to which an authenticated user has access, hence, if you have access to more than one process, you should take the specific procesID from the response of the GetProcess action and then use it to obtain the information of its cases. This means that a manual task should be done between the bot's execution to complete the desired action, which goes against the idea of having a robot completing a process without human intervention. The following image illustrates the previous scenario.

 

AutomationAnywhere062

 

To complete journeys like the one presented above, Automation Anywhere offers a JSON-to-XML Metabot. This Metabot converts a JSON file into an XML file, which can be manipulated so that no user intervention is required during the later process. In that order, it is necessary to first convert the JSON file into an XML file, so that the case's information can be accessed through AA.

 

AutomationAnywhere063

 

Before you start

Before you start manipulating your JSON file in Automation Anywhere, read the following consideratinos:

The steps described in this article apply only for Automation Anywhere Version 11.3.

You can download the JSON-To-XML Metabot here.

 

What you need to do

In this example, we want to get execute a specific workitem of a given case. To process a JSON file returned by an Bizagi bot, complete these steps:

 

1.In your Automation Anywhere Enterprise Client, include the Bizagi Metabot and the JsonToXML Metabot in the Metabot section.

 

AutomationAnywhere064

 

2.Use the Bizagi Metabot to execute the GetWorkitemsByCase action. Make sure to create a local variable to store the Metabot's response.

 

AutomationAnywhere065

 

3.Once you have the JSON with the case's workitems, it is necessary to flatten the file.

a.To do this, select the String Operation command and drag the Length action. Configure the local variable where you saved the JSON as the Source String, and save this in another variable:

 

AutomationAnywhere066

 

b.Add a Variable Operation command and subtract two from the length variable defined in the previous step

 

AutomationAnywhere067

 

c.In the String Operation command, drag the SubString action. Configure the local variable where the JSON is saved as the Source String. Start your SubString from the second position, until the length defined in the previous step. The resultant string must be saved in a variable.

 

AutomationAnywhere068

 

4.After the JSON has been flattened, it is ready to be transformed into an XML. To do this, use the JsonToXmlResponse action from the JsonToXml Metabot. Define as input and as output parameter, the variable where the JSON file is saved.

 

AutomationAnywhere069

 

5.Now, with the XML in the local variable, parse the WorkitemID from it. Drag the StartXMLSession action. Give it a name and use the variable where the XML is saved as an input.

 

AutomationAnywhere070

 

6.Use the Get Node(s) command to obtain the ID node in the XML. use the Session Name defined in the previous step, and for the XPath Expression, type /Root/id.

 

AutomationAnywhere071

 

Now, with the ID stored in a local variable, it is possible to execute the AddStartParameter action to advance the case in the specific workitem.

 


Last Updated 12/12/2024 12:06:08 PM