The GlideElementCurrency2 API provides methods to perform operations on Foreign Exchange (FX) Currency fields (also known as Currency2) within the current GlideRecord.

This API provides methods that enable you to perform the following:
  • Obtain the FX Currency field display string, as entered by the user.
  • Obtain the display value of an FX Currency field.
  • Obtain the reference currency value of an FX Currency field.
  • Obtain the session currency value of an FX Currency field.
  • Set the display value of an FX Currency field.

The GlideElementCurrency2 class has no constructor.

GlideElementCurrency2 - getAsEnteredDisplayValue()

Returns an FX Currency field display string, as entered by the user, from the associated GlideRecord.

For additional information on FX Currency fields, see Setting up and operating FX Currency fields.

Table 1. Parameters
Name Type Description
None
Table 2. Returns
Type Description
String Display currency string as entered by the user.

Example

This example shows how to call the method.

var tablename = 'my_currency2_table';
var setcur2 = new GlideRecord(tablename);
setcur2.initialize();
setcur2.currency_2_field.setDisplayValue('JPY;999999.1234');
setcur2.insert();
gs.info('As entered display value: ' + setcur2.currency_2_field.getAsEnteredDisplayValue());

Output:

As entered display value: ¥999,999.12

GlideElementCurrency2 - getDisplayValue()

Returns the display value of an FX Currency field within the associated GlideRecord.

Depending on how the display_value is set in the FX Currency Configuration [fx_configuration] table, the returned value may be the:
  • Currency value as entered by the user
  • Currency value converted to the session currency (based on the user's locale)
  • Currency value converted to the reference currency

For additional information on FX Currency and the configuration table, see Configure FX Currency global settings.

Table 3. Parameters
Name Type Description
None
Table 4. Returns
Type Description
String Display currency value

Example

This example shows how to call the method.

var tablename = 'my_FXcurrency_table';
var setcur2 = new GlideRecord(tablename);
setcur2.initialize();
setcur2.currency_2_field.setDisplayValue('JPY;999999.1234');
setcur2.insert();
gs.info('Display Value: ' + setcur2.currency_2_field.getDisplayValue());

Output:

Display Value: ¥999,999.12

GlideElementCurrency2 - getReferenceDisplayValue()

Returns the reference currency value of an FX Currency field within the associated GlideRecord.

Reference currency is the common currency into which all currency values in a field are converted. The currency code that the getReferenceDisplayValue() method uses to derive the reference currency is based on the following:
  • If an instance record exists, then the method uses the value in the reference_currency field of the FX Currency [fx_currency2_instance] table.
  • If an instance record does not exist, then the method uses the reference currency that would be set on the instance record when the instance record is eventually created (in the following order):
    • If set, the reference_currency in the FX Currency Configuration [fx_configuration] table.
    • If set, the reference_currency_source in the FX Currency Configuration [fx_configuration] table.
    • System default, system reference currency.

For additional information on the values in the FX Currency Configuration [fx_configuration] table, see Setting up and operating FX Currency fields.

Table 5. Parameters
Name Type Description
None
Table 6. Returns
Type Description
String Reference currency amount for the associated FX Currency display value.

Example

This example assumes the reference currency code is USD and uses the default conversion rate specified in the FX Currency Configuration [fx_configuration] table. The output will change based on locale.

var tablename = 'my_currency2_table';
var setcur2 = new GlideRecord(tablename);
setcur2.initialize();
setcur2.currency_2_field.setDisplayValue('JPY;999999.1234');
setcur2.insert();
gs.info('Reference display value: ' + setcur2.currency_2_field.getReferenceDisplayValue());

Output:

Reference display value: $8,677.99

GlideElementCurrency2 - getSessionDisplayValue()

Returns the session currency value of the associated FX Currency field within the current GlideRecord.

Table 7. Parameters
Name Type Description
None
Table 8. Returns
Type Description
String Currency value converted to the session currency, which is based on the current user's locale.

Example

This example assumes the session locale is language code = eng and country code = USA, and uses the default conversion rate specified in the FX Currency Configuration [fx_configuration] table. The output will change based on locale.

var tablename = 'my_currency2_table';
var setcur2 = new GlideRecord(tablename);
setcur2.initialize();
setcur2.currency_2_field.setDisplayValue('JPY;999999.1234');
setcur2.insert();
gs.info('Session display value: ' + setcur2.currency_2_field.getSessionDisplayValue());

Output:

Session display value: $8,677.99

GlideElementCurrency2 - setDisplayValue(String displayValue)

Sets the display value of an FX Currency field with the specified currency value.

For additional information on FX Currency fields, see Setting up and operating FX Currency fields.

Table 9. Parameters
Name Type Description
displayValue String Value to set in the FX Currency field in the format <currency code>;<currency amount>. You must format the <currency amount> field in the user's locale.

For example, if the user's locale is USA/eng, the passed in <currency amount> would be 123.45. If the user's local is FRA/fre, the passed in <currency amount> would be 123,45.

Table 10. Returns
Type Description
void

Example

This example shows how to call the method.

var tablename = 'my_FXcurrency_table';
var setcur2 = new GlideRecord(tablename);
setcur2.initialize();
setcur2.currency_2_field.setDisplayValue('JPY;999,999.1234');
setcur2.insert();