<< Click to Display Table of Contents >> How to manipulate a JSON file in Automation Anywhere |
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:
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.
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.
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.
2.Use the Bizagi Metabot to execute the GetWorkitemsByCase action. Make sure to create a local variable to store the Metabot's response.
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:
b.Add a Variable Operation command and subtract two from the length variable defined in the previous step
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.
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.
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.
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.
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