From 825423fccb150e5d9c6ba14cebca622345bcfba2 Mon Sep 17 00:00:00 2001 From: AnveshKumar Mupparaju Date: Wed, 1 Oct 2025 08:37:31 +0530 Subject: [PATCH] Custom currency utils --- .../CustomCurrencyUtils/README.md | 19 +++++++++++ .../custom_currency_utils.js | 32 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 Server-Side Components/Script Includes/CustomCurrencyUtils/README.md create mode 100644 Server-Side Components/Script Includes/CustomCurrencyUtils/custom_currency_utils.js diff --git a/Server-Side Components/Script Includes/CustomCurrencyUtils/README.md b/Server-Side Components/Script Includes/CustomCurrencyUtils/README.md new file mode 100644 index 0000000000..5ab9d0974e --- /dev/null +++ b/Server-Side Components/Script Includes/CustomCurrencyUtils/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 diff --git a/Server-Side Components/Script Includes/CustomCurrencyUtils/custom_currency_utils.js b/Server-Side Components/Script Includes/CustomCurrencyUtils/custom_currency_utils.js new file mode 100644 index 0000000000..b2059fc2ad --- /dev/null +++ b/Server-Side Components/Script Includes/CustomCurrencyUtils/custom_currency_utils.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' +};