How to use web service integration for updating currency exchange rates in the [Currencies] lookup
Bpm’online uses a special business process element to call web services and parse their response.
EXAMPLE
Create a business process that will obtain currency exchange rates from the http://api.fixer.io/ web service and update exchange rates on the [Currency rate] detail of the [Currencies] lookup.
Attention
Detailed instructions on setting up integration with the “http://fixer.io/” web service are available in a separate article. Read more >>>
Business process diagram (Fig. 1) elements:
1.Business process custom parameter: “Base currency”, which contains the current value of the [Base currency] system setting.
2.Timer start event: “Start every night” – the process starts daily, at the specified time.
3.Read data system action: “Read base currency” – the process obtains the current base currency name.
4.Call web service system action: “Get currency exchange rate from the Fixer web service” – the process calls web service request method “latest” to obtain exchange rates for the current base currency. The element has 2 outgoing conditional flows:
a.“Success”: the process proceeds to updating the exchange rates if response from the web service has been received.
b.“Error”: the process will terminate if web service call resulted in error or timed out.
5.Add data system actions: add one for each currency whose rate must be modified. For example, “Add EUR exchange rate” – The process adds a record on the [Currency rate] detail for each currency whose rate must be updated. The [Exchange rate] field for each record contains the corresponding exchange rate received from the web service.
6.Parallel gateway AND: this gateway will ensure that the process will end only after all currency rates have been updated.
Bpm’online base currency is set in the [Base currency] system setting. Use a custom parameter to pass the current “Base currency” system setting value to the business process:
1.Click , then click [Parameters] tab and [Add parameter] button. Select “Lookup” parameter type (Fig. 2).
2.Populate parameter properties (Fig. 3):
a.Populate [Title] and [Code] properties.
b.In the [Lookup] field, select the [Currency] lookup.
c.In the [Value] field, click > [System setting] and select the [Base currency] system setting.
The “Start every night” element properties (Fig. 4):
1.In the [Frequency of process start] field, select “Day”.
2.In the [Run every] field block, specify “1 day in 1:30 AM”.
3.Select your time zone and configure other optional properties, if needed.
The “Read base currency” element properties (Fig. 5):
1.In the [Which data read mode to use?] field, select “Read the first record in the selection”.
2.In the [Which object to read data from?] field, select the “Currency” object.
3.Set up the following filter in the [How to filter records?] area: “Id = Base currency”. In this case, “Base currency” is the name of the custom process parameter that you added earlier.
Note
To set the filter: click [Add condition], select the [Id] column; click [<?>] and select [Compare with parameter] command; in the [Select parameter] window, click [Process parameters] tab and select the “Base currency” parameter that you added earlier.
4.In the [What record data should the process read?] field, select “Read data from selected columns only”.
5.Click [Add column] link and select the [Short name] column to have the process read the base currency short name (USD, EUR, etc.) from the lookup.
The “Get currency exchange rate from the Fixer web service” element properties (Fig. 6):
Attention
Before using the [Call web service] element, make sure that you set up integration with the needed web service, using the [Web services] section in the [Studio] workplace. Detailed instructions on setting up integration with the “http://fixer.io/” web service are available in a separate article. Read more >>>
1.In the [Which service to call?] field, select “Currency exchange rate (Fixer)”.
2.In the [Which method to call?] field, select the “Get latest exchange rates” method.
Note
The “http://fixer.io/” web service does not require authentication, so you can use a single [Call web service] element to obtain the response with the required data. If web service requires authentication, then in addition to the request methods for obtaining the necessary data, you need to set up authentication methods. In a process diagram, you will need to add at least two [Call web service] elements: the first one calls the authentication method, and the second [Call web service] element calls the needed functional method, while passing authentication cookie, session Id, etc. as a request parameter.
3.Populate the request parameter values:
a.Map the [Base Currency] parameter to the base currency short name, obtained by the “Read base currency” element. To do this, click > [Process parameter] and select the [Read base currency] element and its parameter [Short name].
b.Specify the value of the [Endpoint] parameter. For the purposes of this process, using the “latest” endpoint will be enough. Enter “latest” value manually.
4.Add an outgoing conditional flow to the [Parallel gateway (AND)]. Set up the condition for moving down this flow only if the outgoing [Success] parameter of the “Get currency exchange rate from the Fixer web service” element is “true”:
a.In the [Condition to move down the flow] field, click .
b.In the opened [Formula] window, on the [Process elements] tab, select the [Get currency exchange rate from the Fixer web service] element.
c.In the right side of the window, double-click the [Success] parameter.
d.Add “==true” text after the parameter variable, so that the whole formula text looks like this: [#Get currency exchange rate from the Fixer web service.Success#]==true
5.Add an outgoing condition flow to the [Terminate] signal. Set up the condition for moving down this flow only if the outgoing [Success] parameter of the “Get currency exchange rate from the Fixer web service” element is “false”. This way, if the web service call ends in error, the process will terminate.
Add an [Add data] element for each exchange rate that must be updated. For example, to update Euro exchange rate, “Add EUR exchange rate” element properties (Fig. 7):
1.In the [Which object to add data to?] field, select the [Exchange rate] object, which is the object of the [Currency rates] detail of the [Currency] lookup.
2.In the [What is the data adding mode?] field, select “Add one record”.
3.In the [Which column values to set?] area, add three fields by clicking [Add field] link.
a.Add the [Currency] field, click > [Lookup] and select the currency, for which the rate will be added (in this case, it is “Euro”).
b.Add the [Exchange rate] field, click > [Process parameter]. In the [Select parameter] window (Fig. 8), select the [Get currency exchange rate from the Fixer web service] element in the left area, and its parameter [RatesEUR] in the right area. This is the exchange rate which will be written.
c.Add the [Start] field, click > [Date and time] –› [Current date and time]. This will record the date and time of the exchange rate update in the [Start] column of the [Currency rates] detail of the [Currency] lookup.
4.Set up [Add data] element for other currency rates in the same way. For example:
a.To update Australian dollar rate: [Currency] – “Australian dollar”, [Exchange rate] – “RatesAUD”, [Start] – “Current date and time”.
b.To update Ruble rate: [Currency] – “Ruble”, [Exchange rate] – “RatesRUB”, [Start] – “Current date and time”.
As a result, the process will automatically start every day, at 1:30 AM, and:
-
check current base currency,
-
call web service for exchange rates in relation to the base currency,
-
write the updated rates for the selected currencies (in this particular case, Euro, Australian dollar and Ruble) on the [Currency rates] detail of the [Currency] lookup (Fig. 9).
If the web service call results in error, the process will terminate.
See also