The form for currency conversion basically consists of the following
components:
In this Part i will first demonstrate how we build the
required form in InfoPath. I will use a static rate of exchange to prove the
calculations embedded in the form are functioning correctly. Then i will
demonstrate how we can use a Web Service to provide the rate for the specific
currencies selected.
In the fields pane right click myFields and select Add, call this new field exchangeRate. For now give this a default value of 1.5.
Select the convert button, and from the ribbon select Manage Rules. Click Add and then select set a fields value. Set the outputAmount field to the value of inputAmount x Rate.
Preview the form and you should now have a functioning multiplication calculation, that is updated each time convert is pressed.
Right click the outputAmount text field select Change Control and choose Calculated Field. This is so the user cannot edit the amount. We don’t want them tampering with the amount of money they are going to get paid!
Finally select the inputAmount text field, and add an Action rule, the rule is to set the outputAmount to be blank, so that the values are always correct.
To recap, we have created a new form that has the components required for us to create a currency conversion component. We have a working calculation working from a button located on the form; however this is using a static rate.
Before Part 2, give your form a bit of jazzing up and you’ll end up with something like this:
In Part
1, we created a new form that has the components required for us to
create a currency conversion component. We have a working calculation working
from a button located on the form, however this is using a static rate.
At the end of Part 1 we ended up with a form that looked a little like
this:
We now are going to continue and achieve the following:
After a bit of hunting I found a web service that would suit the needs of
this project. It can be accessed using the following URL: http://www.webservicex.net/CurrencyConvertor.asmx
From the description this does exactly what we need it to. Adding this in to
InfoPath couldn’t be simpler. But as this web service is out on the web we need
to change our form in to full trust mode. To do this click File
-> Form Options and from the left select Security
and Trust, from here you can uncheck Automatically determine
security level and select Full Trust.
Now we are ready to add our web service. On the Fields pane
click Manage Data Connections. Click on Add
and then follow the wizard as illustrated.
Leave the defaults and click Next.
Leave SOAP Web Service selected and click
Next.
Enter the URL of the web service into the location box and click
Next.
The web service, has only a single method ConversionRate
select it and click Next.
On this screen you are able to set default values, notice that when you do
you get a great drop down list of valid items that will come in handy later. I’m
from Australia so have set both values to AUD to begin with. Click Next,
Next and finally Finish.
You have now successfully added the web service in to InfoPath. The next step
will be to add those useful drop downs we just saw in to the form for the end
user to utilise in selecting valid currencies.
In the Fields pane select the drop down that currently has
Main selected; select the secondary data source of
ConversionRate. Expand the structure, and inside queryFields
you can see the two values we set earlier, FromCurrency and
ToCurrency.
Simply drag and drop these on to the form, a menu will appear and you will
want to select drop down box as the type of field to utilise. If you preview the
form now your drop down lists should be functional.
Brilliant, we have all the values the web service support so we should be
safe from errors. Next open the properties of the exchangeRate
field, set the default value to the ConversionRateResult as
shown below. Ensure that Refresh value when formula is
recalculated is checked.
Finally we just need to edit the rules on our Convert
button, select the Convert button and then select
Manage Rules select the rule we created earlier, most likely
with its default name Rule 1. Add a new action of type
Query for Data. We only have one web service currently so by
default the data connection selected is ConversionRate click
OK. We need to ensure that we query for data before setting the
outputAmount there for highlight the action that we just added
and select Move Up.
You should end up with the two actions like this.
That’s It! Preview your form, enter a value and select your from and to
currency and hit the convert button. We now have the value coming back that we
expect.
To recap, we created a new InfoPath form, laid out some controls with a
couple of rules, connected a conversion rate web service and hooked it up all
together to make a InfoPath currency conversion form. These components can now
be used various ways in many other forms that would require currency conversion.
- An input value
- A from currency
- A to currency
- A submit button

- Create a new Blank Form in InfoPath 2010.
- Add the following controls to the form:
- A text field called inputAmount, configure this as a Decimal (double).
- A text field called outputAmount, configure this as a Decimal (double).
- A button called convert

In the fields pane right click myFields and select Add, call this new field exchangeRate. For now give this a default value of 1.5.

Select the convert button, and from the ribbon select Manage Rules. Click Add and then select set a fields value. Set the outputAmount field to the value of inputAmount x Rate.

Preview the form and you should now have a functioning multiplication calculation, that is updated each time convert is pressed.

Right click the outputAmount text field select Change Control and choose Calculated Field. This is so the user cannot edit the amount. We don’t want them tampering with the amount of money they are going to get paid!
Finally select the inputAmount text field, and add an Action rule, the rule is to set the outputAmount to be blank, so that the values are always correct.

To recap, we have created a new form that has the components required for us to create a currency conversion component. We have a working calculation working from a button located on the form; however this is using a static rate.
Before Part 2, give your form a bit of jazzing up and you’ll end up with something like this:

Part 2

- Connect to a Currency Conversion Web Service.
- Provide drop down lists of available currencies.
- Set the Exchange Rate relevant to our selected values.












No comments:
Post a Comment