diff --git a/Client-Side Components/Client Scripts/Price field restriction to one currency/README.md b/Client-Side Components/Client Scripts/Price field restriction to one currency/README.md new file mode 100644 index 0000000000..725a1c8801 --- /dev/null +++ b/Client-Side Components/Client Scripts/Price field restriction to one currency/README.md @@ -0,0 +1,13 @@ + +# Client Script - Set Price type field to only one currency + +In a multi currecny enabled servicenow environment, if you have a requirement to enable only one currency choice for a particular table and field of type Price. + +## Usage + +- Create a new client script +- Set the type to OnLoad. +- Copy the script to your client script. +- Update the in the client script to 'Your field name' +- Add your currency code and symbol in place of USD & $ +- Save \ No newline at end of file diff --git a/Client-Side Components/Client Scripts/Price field restriction to one currency/price_field_restriction_to_one_currency.js b/Client-Side Components/Client Scripts/Price field restriction to one currency/price_field_restriction_to_one_currency.js new file mode 100644 index 0000000000..c2fed5261f --- /dev/null +++ b/Client-Side Components/Client Scripts/Price field restriction to one currency/price_field_restriction_to_one_currency.js @@ -0,0 +1,10 @@ +function onLoad(){ + // Remove all currency options + g_form.clearOptions('.currency_type'); + + // Add only one currency option (e.g., USD) + g_form.addOption('.currency_type', 'USD', '$'); + + // Set the currency field to the only available option + g_form.setValue('.currency_type', 'USD'); +} \ No newline at end of file diff --git a/Server-Side Components/Script Includes/CurrencyUtilities/CustomCurrencyUtils.js b/Server-Side Components/Script Includes/CurrencyUtilities/CustomCurrencyUtils.js new file mode 100644 index 0000000000..4777191b82 --- /dev/null +++ b/Server-Side Components/Script Includes/CurrencyUtilities/CustomCurrencyUtils.js @@ -0,0 +1,32 @@ +var CustomCurrencyUtils = Class.create(); +CustomCurrencyUtils.prototype = { + initialize: function() {}, + + /* + Parameters: + record_id : sys_id of the record + field : name of the currency/price field for which the reference currency value is needed + + Returns: Object + - Currnecy and Value : returns currncy code and value of the field in reference currency + - false : if the record not found or field is invalid + */ + + getReferenceValue: function(record_id, field) { + var priceGr = new GlideRecord('fx_price'); + priceGr.addQuery('id', record_id); + priceGr.addQuery('field', field); + priceGr.setLimit(1); + priceGr._query(); + + if (priceGr._next()) { + return { + currency: priceGr.getValue('reference_amount'), + value: priceGr.getValue('reference_currency') + } + } + return false; + }, + + type: 'CustomCurrencyUtils' +}; \ No newline at end of file diff --git a/Server-Side Components/Script Includes/CurrencyUtilities/README.md b/Server-Side Components/Script Includes/CurrencyUtilities/README.md new file mode 100644 index 0000000000..5ab9d0974e --- /dev/null +++ b/Server-Side Components/Script Includes/CurrencyUtilities/README.md @@ -0,0 +1,19 @@ +# CustomCurrencyUtils + +## Purpose + +`CustomCurrencyUtils.js` provides utility functions for handling custom currency operations within your application. It facilitates formatting, parsing, and conversion of currency values, supporting both standard and custom currency types. These utilities help ensure consistency and accuracy when displaying or processing monetary values, especially in scenarios involving multiple currencies are enabled. + +## Usefulness + +- Centralizes currency-related logic, reducing code duplication. +- Simplifies integration of custom currencies by abstracting formatting and conversion details. +- Enhances maintainability by providing a single location for currency utilities. +- Improves user experience by ensuring currency values are presented clearly and consistently. + +## Usage + +1. **Get Currency value in reference currency:** + ```js + var ref_currency = new CustomCurrencyUtils().getReferenceValue('', ''); + ``` \ No newline at end of file