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,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 <price_field> in the client script to 'Your field name'
- Add your currency code and symbol in place of USD & $
- Save
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function onLoad(){
// Remove all currency options
g_form.clearOptions('<price_field>.currency_type');

// Add only one currency option (e.g., USD)
g_form.addOption('<price_field>.currency_type', 'USD', '$');

// Set the currency field to the only available option
g_form.setValue('<price_field>.currency_type', 'USD');
}
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'
};
19 changes: 19 additions & 0 deletions Server-Side Components/Script Includes/CurrencyUtilities/README.md
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>');
```
Loading