- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2022 06:43 AM
Hello!
There is a Cost currency field in the alm_hardware table.
I created another currency field called Cost (USD).
The objective is to display the USD equivalent to this custom field.
The USD equivalent is taken from the Reference amount field in the fx_currency_instance table.
I have created a BR that is triggered when the Cost field changes.
var gr = new GlideRecord('fx_currency_instance');
gr.addQuery('id', current.sys_id);
gr.addEncodedQuery('field=cost');
gr.query();
if (gr.next()) {
var usd = gr.getValue('reference_amount');
}
gs.addInfoMessage(usd);
current.u_cost_usd = usd;
The issue is the 'usd' value is not saved to the u_cost_usd field.
Any idea why the field is not updated?
Please help!
Thank you.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2022 07:27 AM
Hi,
Please create after BR Like below:
and use below script:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('fx_currency_instance');
gr.addQuery('id', current.sys_id);
gr.addEncodedQuery('field=cost');
gr.query();
if (gr.next()) {
var usd = gr.getValue('reference_amount');
}
gs.addInfoMessage(usd);
current.u_cost_usd = usd;
current.setWorkflow(false);
current.update();
})(current, previous);
Thanks,
Anil Lande
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2022 07:19 AM
Hi,
I hope you have cerate before update/insert BR. If not then please change it to before.
Thanks,
Anil Lande
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2022 07:27 AM
Hi,
Please create after BR Like below:
and use below script:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('fx_currency_instance');
gr.addQuery('id', current.sys_id);
gr.addEncodedQuery('field=cost');
gr.query();
if (gr.next()) {
var usd = gr.getValue('reference_amount');
}
gs.addInfoMessage(usd);
current.u_cost_usd = usd;
current.setWorkflow(false);
current.update();
})(current, previous);
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2022 01:03 AM
I had to use an After BR because when the Cost field is updated, the value that is saved in the Cost (USD) field is the previous value. Is there a reason why this should be a Before BR?
The missing line in my script was the current.update().
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2022 01:11 AM
This worked! Thank you.
A couple of questons though.
1. Why does it have to be a Before BR?
2. Why the need to setWorkflow to false?