One of the best things about being in IT, is problem solving. I do enjoy coming up with solutions to problems. Todays, was around getting Nintex Workflow to parse XE.com data. If you don’t know what XE.com is, it’s an online currency converter. Given one currency, it can convert it to any number of other currencies. Quite handy if you’re planning on travel, shopping or thinking about investments.
The specifications of the data that comes back from the XE.com API is defined here: http://www.xe.com/xecurrencydata/specifications.php
This blog post is not about communicating with XE.com. This assumes you already have an account and either use a Nintex Workflow Web Request action or some other means to get at the data from XE.com. This is post is about taking that data and extracting out the information you need. So in fact, this post is actually about 2 Nintex Workflow User Defined Actions that will help.
Getting All the Data
When you get a response from XE.com, the format depends on what you ask for. In this post, I’m only dealing with the XML format you get back. You can also get JSON and CSV data.
The first UDA is the “ParseXEdotCOM Data UDA”. The User Defined Action will give you all the data back from the XML.
This UDA takes one input parameter, which is the XML that you get from XE.com. The output of this UDA is a number of values. The number of conversions, what you’re converting from (which you should know anyway), then two collections which will be the same size. The list of currencies and the list of their conversion rates.
The UDA design looks like this :
You can see that it’s not very complicated. Since the Query XML action allows for multiple XPath queries, you don’t need to have multiple actions.
Since the XML has it’s own defined namespace, we have to add the defaultNS namespace to all nodes you use in the XPath expression.
The last action is the Collection operation, which is straight forward, since all it’s doing is a count on one of the collections to get the number of conversions there are in the XML.
As part of the downloads section at the bottom of this post, I’ll make both UDAs and the test Workflow available for your play with in your environment.
Getting a Single Conversion Value
Although getting all that data in collections can be useful, sometimes you just want to get out a single value back from the XML. I may have asked for multiple conversions from XE.com, but in a particular part of my workflow, I only want to get back the value for EUR or AUD. The previous UDA is just overkill. So in comes this UDA, which I can reuse in different parts of my workflow.
You can see in the parameter list, that the types of parameters is the opposite of the previous UDA. You pass in 3 input parameters (XML, From Currency Code and To Currency Code). This will allow the UDA to confirm that the conversion XML we have is actually for the From currency and it’ll get the conversion rate and store that in the Output variable (Output Rate).
Again, the UDA design is quite straight forward, with a Query XML action that looks for the From Currency, to make sure it matches what was requested from the Workflow.
The Set a Condition action simply compares the From parameter to the “textFromCode” variable, to make sure they match. If they do, the second Query XML action performs quite an elaborate XPath query.
The XPath expression is looking for a “rate” node, where it’s child “currency” node is equal to what was passed in to the UDA, and it then gets back the other child node value, which is “mid”. That is the exchange rate.
Example of the XML
The XML you can get back from XE.com will look like this:
<?xml version=”1.0″ ?>
You will get multiple “rate’ nodes, if you request different currency conversions. In the workflow available in the Downloads section below, I simply pasted the above XML into a Build String action that I use through out the workflow and UDAs.
Downloading a Nintex Workflow Trial
Download the Parse XEdotCOM Data UDA– Download, Unzip and import into the Nintex Workflow Create User Defined Action designer page
Download the Conversion Rate from XEdotCOM UDA– Download, Unzip and import into the Nintex Workflow Create User Defined Action designer page
Download the Test Workflow– Download, Unzip and import into the Nintex Workflow designer page