Need some help to understand for currency field use in ref in one of my application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I am using a currency code field that references values from the fx_currency table. However, when I save the form, the currency code is not retained—the field value disappears and is not visible after saving.
Could someone please suggest why this might be happening and what configuration or issue I should check in this case?
Can anyone suggest I wanna keep the selected currency code in the form, then what kind of changes are required?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
it seems you are trying to Refer to that table while creating the dictionary?
did you try creating dictionary in normal way from sys_dictionary?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I tried using a reference field, and I also verified the dictionary configuration for that field, but it still doesn’t work or retain the value. I’m looking for guidance on the underlying structure of the currency table, as I believe understanding that may help resolve the issue. I need the code field from the fx_currency table using reference, but in that table code field is not a unique one. Have a look
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I didn't get your question
-> you are able to create a reference field pointing to fx_currency table
-> what is not retained?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Fixed – Field value selection after saving.
Working on – I want users to select a currency and enter values in the next 3 financial fields after the non-edit field. When they submit the form, those values should be converted into USD.
I tested the API using an Outbound REST Message, and I got a 200 response, which is correct.
Based on that, I created a Script Include to call the API, read the response, and convert it into JSON.
To trigger the Script Include, I tried a Business Rule (Before Insert/Update) and also Async, but neither worked. I then added gs.eventQueue() inside the Business Rule. The event is created and it triggers the Event Action.
In the Event Action, I call the Script Include and use the returned FX rate to convert from the selected Base Currency (local currency) to USD for all three fields. Unfortunately, the conversion is still not running. I tried many times—can someone identify the issue in my approach or code?
Script include is here -
var FXRateService = Class.create();
FXRateService.prototype = {
getRateTOUSD: function(baseCurrency) {
if (!baseCurrency || baseCurrency == 'USD') {
return 1.0;
}
var rm = new sn_ws.RESTMessageV2('x_1285971_wealth_m.GetExchangeRate', 'Default GET');
// This line is essential for passing the variable to the configured endpoint URL
rm.setStringParameter('base_currency_code', baseCurrency);
var repsonse = rm.execute();
var httpStatus = repsonse.getStatusCode();
if (httpStatus != 200) {
gs.error('FX API HTTP error ' + httpStatus);
return null;
}
var responseBody = repsonse.getBody();
var json = JSON.parse(responseBody);
if (json && json.conversion_rates && json.conversion_rates.USD) {
return parseFloat(json.conversion_rates.USD);
}
gs.error('FX API unexpected response for ' + baseCurrency + ': ' + responseBody);
return null;
},
type: 'FXRateService'
};BR is here before using for insert and update
(function executeRule(current, previous) {
var isNew = current.isNewRecord();
var currencyChanged = current.currency.changes();
if (!isNew && !currencyChanged) {
return;
}
gs.info("BR firing FX event for sys_id=" + current.sys_id + " currency=" + current.currency);
gs.eventQueue(
'x_1285971_wealth_m.wm.fx.convert',
current,
current.sys_id.toString(),
current.currency.toString()
);
})(current, previous);
Last Event action
(function runAction(current, event, parm1, parm2) {
gs.info("SA_FX_to_USD STARTED. sysId=" + parm1 + " currency=" + parm2);
var rec = new GlideRecord('x_1285971_wealth_m_client');
if (!rec.get(parm1)) {
gs.error("SA_FX_to_USD: record not found for sys_id=" + parm1);
return;
}
var fxService = new FXRateService();
var rate = fxService.getRateTOUSD(parm2);
gs.info("SA_FX_to_USD: rate returned = " + rate);
if (!rate) {
gs.error("SA_FX_to_USD: unable to fetch rate for " + parm2);
return;
}
rec.fx_rate_to_usd = rate;
if (rec.annual_income) {
rec.annual_income = parseFloat(rec.annual_income) * rate;
}
if (rec.net_worth) {
rec.net_worth = parseFloat(rec.net_worth) * rate;
}
if (rec.liquid_net_worth) {
rec.liquid_net_worth = parseFloat(rec.liquid_net_worth) * rate;
}
rec.update();
gs.info("SA_FX_to_USD COMPLETED for " + parm1);
})(current, event, parm1, parm2);
I'll share the form where I am trying to add with label fields, and the system name shows in there.
