Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Get current exchange rates

Sergio Gadelha
Tera Contributor

Hi, I'm using the script below to get total cost of a event, considering the system default currency (USD), but the exchange rates aren't updated.

How can I get this rates updated?

var totalCost = Class.create();

totalCost.prototype = {

      initialize: function(mrkevent) {

              this.mrkevent = mrkevent;

      },

      getCost: function() {

              var cost = 0;

              //Get the total cost of all equipment for this event

              var equipment = new GlideRecord('x_73586_marketing_equipment_request');

              equipment.addQuery('marketing_event', this.mrkevent);

              equipment.query();

              while(equipment.next()){

                      cost = cost + parseFloat(equipment.cost.getSessionValue());

              }

              return cost;

      },

      type: 'totalCost'

};

Thanks!

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Sérgio,



Exchange rates are updated nightly by a scheduled job.


Set a conversion rate


View solution in original post

4 REPLIES 4

Chuck Tomasi
Tera Patron

Hi Sérgio,



Exchange rates are updated nightly by a scheduled job.


Set a conversion rate


And if i want to update when any record is inserted at any table of my Application?



Thanks!


You can write a business rule that uses the same script as the scheduled job and run it to get the latest exchange rates. I would weigh the cost of frequent visits to the currency exchange against the need to refresh more than once a day. You might want to consider just updating the scheduled job to run ever couple hours.


SaschaWildgrube
ServiceNow Employee
ServiceNow Employee

DevTools is a scoped application with many helpful scripts ready to be re-used.

The built-in currency conversion API object (GlideCurrencyConverter) is a bit tricky to use.

Here you can find a nice wrapper function for currency conversion based on the ServiceNow OOTB functionality:

https://github.com/saschawildgrube/servicenow-devtools/blob/master/update/sys_script_include_6f29745...