Skip to content

Commit 134ad3a

Browse files
Currency utilities for server side operations
1 parent 1c8a590 commit 134ad3a

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var CustomCurrencyUtils = Class.create();
2+
CustomCurrencyUtils.prototype = {
3+
initialize: function() {},
4+
5+
/*
6+
Parameters:
7+
record_id : sys_id of the record
8+
field : name of the currency/price field for which the reference currency value is needed
9+
10+
Returns: Object
11+
- Currnecy and Value : returns currncy code and value of the field in reference currency
12+
- false : if the record not found or field is invalid
13+
*/
14+
15+
getReferenceValue: function(record_id, field) {
16+
var priceGr = new GlideRecord('fx_price');
17+
priceGr.addQuery('id', record_id);
18+
priceGr.addQuery('field', field);
19+
priceGr.setLimit(1);
20+
priceGr._query();
21+
22+
if (priceGr._next()) {
23+
return {
24+
currency: priceGr.getValue('reference_amount'),
25+
value: priceGr.getValue('reference_currency')
26+
}
27+
}
28+
return false;
29+
},
30+
31+
type: 'CustomCurrencyUtils'
32+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# CustomCurrencyUtils
2+
3+
## Purpose
4+
5+
`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.
6+
7+
## Usefulness
8+
9+
- Centralizes currency-related logic, reducing code duplication.
10+
- Simplifies integration of custom currencies by abstracting formatting and conversion details.
11+
- Enhances maintainability by providing a single location for currency utilities.
12+
- Improves user experience by ensuring currency values are presented clearly and consistently.
13+
14+
## Usage
15+
16+
1. **Get Currency value in reference currency:**
17+
```js
18+
var ref_currency = new CustomCurrencyUtils().getReferenceValue('<sys_id>', '<your_field>');
19+
```

0 commit comments

Comments
 (0)