Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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('<sys_id>', '<your_field>');
```
Original file line number Diff line number Diff line change
@@ -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'
};
Loading