---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideCurrencyConverter - Scoped

# GlideCurrencyConverter - Scoped {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read

The GlideCurrencyConverter API provides methods to convert one currency value to another, such as converting US dollars into European euros.

You can instantiate the GlideCurrencyConverter object and define the source and destination
currencies during instantiation using GlideCurrencyConverter(from, to). You
can also instantiate the object without these values and define them later using the
setFromCurrency() and setToCurrency() methods. These
values and the amount to convert must be set before calling the convert()
method to perform the currency conversion. To set the amount to convert, use the
setAmount() method.  
The GlideCurrencyConverter() API also provides optional methods that enable you to:

* Set the date and time for which to perform the conversion, setDateTime(). By setting the date and time, the rate that is used in the conversion calculation is that for the specified date and time, instead of the default of the current date and time.
* Set the rate table to use in the conversion, setRateTable(). By default the conversion uses the fx_system_rate table however, you can define custom rate tables for your instance. For additional information on creating rate tables, see [Add conversion rates using a custom
  rate table](https://www.servicenow.com/docs/access?context=custom-rate-table&version=xanadu&pubname=xanadu-platform-administration&ft:locale=en-US).
{#GlideCurrencyConverterScopedAPI__ul_wx1_qnw_ljb}

This class runs is in the `sn_currency` namespace.

## GlideCurrencyConverter - GlideCurrencyConverter() {#ariaid-title2}

Instantiates a GlideCurrencyConverter object.
{#Scoped-GCC-GlideCurrConv__table_xzn_5fw_ljb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 1. Parameters]

{#Scoped-GCC-GlideCurrConv__table_xzn_5fw_ljb}  
This example shows how to call the method.

    var conv = new sn_currency.GlideCurrencyConverter();

## GlideCurrencyConverter - GlideCurrencyConverter(String from, String to) {#ariaid-title3}

Instantiates a GlideCurrencyConverter object and sets the source and
destination country codes to use in the currency conversion.
{#Scoped-GCC-GlideCurrConv_S_S__table_a4p_kjp_cy__entry__3}

| Name | Type | Description |
|-|-|-|
| from | String | Three-letter ISO 3166 country code of the source currency. |
| to | String | Three-letter ISO 3166 country code of the converted currency. |
[Table 2. Parameters]

{#Scoped-GCC-GlideCurrConv_S_S__table_a4p_kjp_cy}  
This example shows how to call the method.

    var conv = new sn_currency.GlideCurrencyConverter('EUR', 'USD');

## GlideCurrencyConverter - convert() {#ariaid-title4}

Executes the currency converter.
Call this method after calling other GlideCurrencyConverter methods that
construct the currency conversion, such as setAmount(),
setRateTable(), and setDate().
{#Scoped-GCC-convert__table_qyh_2hq_cy__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 3. Parameters]

{#Scoped-GCC-convert__table_qyh_2hq_cy} {#Scoped-GCC-convert__table_ryh_2hq_cy__entry__2}

| Type | Description |
|-|-|
| Object | If the conversion is successful, returns CurrencyExchangeValue object. If unsuccessful, returns "null". CurrencyExchangeValue { Rate: Number, OriginalAmount: Number, Amount: Number, fromCurrency: String, toCurrency: String, rateSysId: String } Rate: Number. Exchange rate used in the conversion. OriginalAmount: Number. Source currency amount. Amount: Number. Converted amount (OriginalAmount \* Rate). fromCurrency: String. Three-letter ISO 3166 country code of the source currency. toCurrency: String. Three-letter ISO 3166 country code of the converted currency. rateSysId: String. Sys_id of the rate table record used to calculate the conversion. |
[Table 4. Returns]

{#Scoped-GCC-convert__table_ryh_2hq_cy}  
This example shows how to call the method.

    var conv = new sn_currency.GlideCurrencyConverter('EUR', 'USD');
    conv.setAmount(100);
    gs.info(conv.convert());

Output:

    CurrencyExchangeValue{Rate = 1.0777, OriginalAmount = 100, Amount = 107.7700, fromCurrency = 'EUR', toCurrency = 'USD', rateSysId = '2ed537fcb271937adb'}

## GlideCurrencyConverter - setAmount(String amount) {#ariaid-title5}

Sets the amount of currency to convert.
{#Scoped-GCC-setAmount_S__table_pq4_yxp_cy__entry__3}

| Name | Type | Description |
|-|-|-|
| amount | String | Currency amount to convert. This value must be unformatted except for a decimal point to denote fractional currency. For example, 1234.56 is valid, 1,234.56 is invalid. |
[Table 5. Parameters]

{#Scoped-GCC-setAmount_S__table_pq4_yxp_cy} {#Scoped-GCC-setAmount_S__table_qq4_yxp_cy__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 6. Returns]

{#Scoped-GCC-setAmount_S__table_qq4_yxp_cy}  
This example shows how to call the method.

    var conv = new sn_currency.GlideCurrencyConverter('EUR', 'USD');
    conv.setAmount(100);

## GlideCurrencyConverter - setDateTime(Object date) {#ariaid-title6}

Sets the currency conversion date and time.
This date and time determines the conversion rate that is used to convert the currency. If
this method is not called before the GlideCurrencyConverter.convert()
method, the conversion is performed using the rate for the current date/time.
{#Scoped-GCC-setDateTime_O__table_zxg_cfc_ljb__entry__3}

| Name | Type | Description |
|-|-|-|
| date | GlideDateTime | Date/time for which to calculate the currency conversion. This value determines the rate that is used in the conversion. |
[Table 7. Parameters]

{#Scoped-GCC-setDateTime_O__table_zxg_cfc_ljb} {#Scoped-GCC-setDateTime_O__table_ayg_cfc_ljb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 8. Returns]

{#Scoped-GCC-setDateTime_O__table_ayg_cfc_ljb}  
The following example shows how to call this method.

    var conv = new sn_currency.GlideCurrencyConverter('EUR', 'USD');
    conv.setAmount(100);
    var gd = new GlideDateTime("2019-01-03 11:00:00");
    conv.setDateTime(gd);
    gs.info(conv.convert());

Output:

    CurrencyExchangeValue{fOriginalAmount=100, fOriginalCurrency='EUR', fRate=1.061, fAmount=106.1, fCurrency='USD', fRateSysId='4555525f5553445f3130303030313031'}

## GlideCurrencyConverter - setFromCurrency(String from) {#ariaid-title7}

Sets the country code of the source currency.
{#Scoped-GCC-setFromCurrency_S__table_wtv_g5p_cy__entry__3}

| Name | Type | Description |
|-|-|-|
| from | String | Three-letter ISO 3166 country code of the source currency. |
[Table 9. Parameters]

{#Scoped-GCC-setFromCurrency_S__table_wtv_g5p_cy} {#Scoped-GCC-setFromCurrency_S__table_xtv_g5p_cy__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 10. Returns]

{#Scoped-GCC-setFromCurrency_S__table_xtv_g5p_cy}  
This example shows how to call the method.

    var conv = new sn_currency.GlideCurrencyConverter().setFromCurrency('FRA');

## GlideCurrencyConverter - setRateTable(String rateTable) {#ariaid-title8}

Defines the rate table to use in the currency conversion.
If this method is not called before the GlideCurrencyConverter.convert()
method is called, the conversion is performed using the fx_system_rate table. All custom
rate tables must extend the fx_conversion_rate table. For additional information on creating
rate tables, see [Add conversion rates using a custom
rate table](https://www.servicenow.com/docs/access?context=custom-rate-table&version=xanadu&pubname=xanadu-platform-administration&ft:locale=en-US).
{#Scoped-GCC-setRateTable_S__table_kmn_swp_cy__entry__3}

| Name | Type | Description |
|-|-|-|
| rateTable | String | Name of the rate table to use in the currency conversion. |
[Table 11. Parameters]

{#Scoped-GCC-setRateTable_S__table_kmn_swp_cy} {#Scoped-GCC-setRateTable_S__table_lmn_swp_cy__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 12. Returns]

{#Scoped-GCC-setRateTable_S__table_lmn_swp_cy}  
This example shows how to call the method.

    var conv = new sn_currency.GlideCurrencyConverter('EUR', 'USD');
    conv.setRateTable(custom_rate_table);

## GlideCurrencyConverter - setToCurrency(String to) {#ariaid-title9}

Sets the country code of the destination currency.
{#Scoped-GCC-setToCurrency_S__table_wwy_gwp_cy__entry__3}

| Name | Type | Description |
|-|-|-|
| to | String | Three-letter ISO 3166 country code of the source currency. |
[Table 13. Parameters]

{#Scoped-GCC-setToCurrency_S__table_wwy_gwp_cy} {#Scoped-GCC-setToCurrency_S__table_xwy_gwp_cy__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 14. Returns]

{#Scoped-GCC-setToCurrency_S__table_xwy_gwp_cy}  
This example shows how to call the method.

    var conv = new sn_currency.GlideCurrencyConverter().setToCurrency('USA');


