{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":790,"path":"api-reference/server-api-reference/GlideElementCurrency2ScopedAPI.md","title":"GlideElementCurrency2 - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideElementCurrency2- Scoped\n\nThe GlideElementCurrency2 API provides methods to perform operations on Foreign Exchange \\(FX\\) Currency fields \\(also known as Currency2\\) within the current GlideRecord.\n\nThis API provides methods that enable you to perform the following:\n\n-   Obtain the FX Currency field display string, as entered by the user.\n-   Obtain the display value of an FX Currency field.\n-   Obtain the reference currency value of an FX Currency field.\n-   Obtain the session currency value of an FX Currency field.\n-   Set the display value of an FX Currency field.\n\nThe GlideElementCurrency2 class has no constructor.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## GlideElementCurrency2 - getAsEnteredDisplayValue\\(\\)\n\nReturns an FX Currency field display string, as entered by the user, from the associated GlideRecord.\n\nFor additional information on FX Currency fields, see [Setting up and operating FX Currency fields](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/fx-currency.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Display currency string as entered by the user.|\n\nThis example shows how to call the method.\n\n```\nvar tablename = 'my_currency2_table';\nvar setcur2 = new GlideRecord(tablename);\nsetcur2.initialize();\nsetcur2.currency_2_field.setDisplayValue('JPY;999999.1234');\nsetcur2.insert();\ngs.info('As entered display value: ' + setcur2.currency_2_field.getAsEnteredDisplayValue());\n```\n\nOutput:\n\n```\nAs entered display value: ¥999,999.12\n```\n\n## GlideElementCurrency2 - getDisplayValue\\(\\)\n\nReturns the display value of an FX Currency field within the associated GlideRecord.\n\nDepending on how the display\\_value is set in the FX Currency Configuration \\[fx\\_configuration\\] table, the returned value may be the:\n\n-   Currency value as entered by the user\n-   Currency value converted to the session currency \\(based on the user's locale\\)\n-   Currency value converted to the reference currency\n\nFor additional information on FX Currency and the configuration table, see [Configure FX Currency global settings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/fx-currency-configure.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Display currency value|\n\nThis example shows how to call the method.\n\n```\nvar tablename = 'my_FXcurrency_table';\nvar setcur2 = new GlideRecord(tablename);\nsetcur2.initialize();\nsetcur2.currency_2_field.setDisplayValue('JPY;999999.1234');\nsetcur2.insert();\ngs.info('Display Value: ' + setcur2.currency_2_field.getDisplayValue());\n```\n\nOutput:\n\n```\nDisplay Value: ¥999,999.12\n```\n\n## GlideElementCurrency2 - getReferenceDisplayValue\\(\\)\n\nReturns the reference currency value of an FX Currency field within the associated GlideRecord.\n\nReference 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:\n\n-   If an instance record exists, then the method uses the value in the reference\\_currency field of the FX Currency \\[fx\\_currency2\\_instance\\] table.\n-   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\\):\n    -   If set, the **reference\\_currency** in the FX Currency Configuration \\[fx\\_configuration\\] table.\n    -   If set, the **reference\\_currency\\_source** in the FX Currency Configuration \\[fx\\_configuration\\] table.\n    -   System default, system reference currency.\n\nFor additional information on the values in the FX Currency Configuration \\[fx\\_configuration\\] table, see [Setting up and operating FX Currency fields](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/fx-currency.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Reference currency amount for the associated FX Currency display value.|\n\nThis 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.\n\n```\nvar tablename = 'my_currency2_table';\nvar setcur2 = new GlideRecord(tablename);\nsetcur2.initialize();\nsetcur2.currency_2_field.setDisplayValue('JPY;999999.1234');\nsetcur2.insert();\ngs.info('Reference display value: ' + setcur2.currency_2_field.getReferenceDisplayValue());\n```\n\nOutput:\n\n```\nReference display value: $8,677.99\n```\n\n## GlideElementCurrency2 - getSessionDisplayValue\\(\\)\n\nReturns the session currency value of the associated FX Currency field within the current GlideRecord.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Currency value converted to the session currency, which is based on the current user's locale.|\n\nThis 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.\n\n```\nvar tablename = 'my_currency2_table';\nvar setcur2 = new GlideRecord(tablename);\nsetcur2.initialize();\nsetcur2.currency_2_field.setDisplayValue('JPY;999999.1234');\nsetcur2.insert();\ngs.info('Session display value: ' + setcur2.currency_2_field.getSessionDisplayValue());\n```\n\nOutput:\n\n```\nSession display value: $8,677.99\n```\n\n## GlideElementCurrency2 - setDisplayValue\\(String displayValue\\)\n\nSets the display value of an FX Currency field with the specified currency value.\n\nFor additional information on FX Currency fields, see [Setting up and operating FX Currency fields](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/fx-currency.md).\n\n<table id=\"table_enw_5jd_fy\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ndisplayValue\n\n</td><td>\n\nString\n\n</td><td>\n\nValue 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.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\nThis example shows how to call the method.\n\n```\nvar tablename = 'my_FXcurrency_table';\nvar setcur2 = new GlideRecord(tablename);\nsetcur2.initialize();\nsetcur2.currency_2_field.setDisplayValue('JPY;999,999.1234');\nsetcur2.insert();\n```\n\n"}}