
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2024 06:41 AM
Hi All,
I have recently enabled Multi-Currency in my instance, I have both USD and Yaun as currencies.
When I do the aggregation of two fields and try to set the value into another currency field I get the aggregate in USD instead of Yaun as displayed in my screenshot.
Below is my code which I am running in OnBefore BR (should I change it to run OnAfter)
(function executeRule(current, previous /*null when async*/ ) {
var currencyCode = current.total_app_budget.getCurrencyCode();
var total = current.total_app_budget + current.total_app_expense;
current.not_to_exceed_amount.setValue(currencyCode + ";" + total);
})(current, previous);
I also tried to do something like the below using the background script still to no avail.
var current = new GlideRecord("table_name");
if (current.get("sys_id of the record")) {
var currencyCode = current.total_app_budget.getCurrencyCode();
gs.info(currencyCode +"CurrencyCode");
var totalBudget = current.total_app_budget.getCurrencyDisplayValue();
var totBud = trim(totalBudget.toString().split("¥").splice(1));
totBud = (totBud/1);
gs.info('FieldType1: '+typeof(totalBudget)+ ' Value: '+totBud);
var totalExpense = current.total_app_expense.getCurrencyDisplayValue();
var totExp = parseFloat(totalExpense.toString().replace("¥",""));
gs.info('FieldType2: '+typeof(totalExpense) + ' Value2: '+totExp);
var total = totBud + totExp;
gs.info('Total & Type '+total + ' type: '+typeof(total));
// current.not_to_exceed_amount.setValue(currencyCode + ";" + total);
}
Request your assistance to get the aggregation in the required currency and set the value in the field
Regards,
Imran
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2024 08:48 AM
One of my colleague was able to sort it out for me
(function executeRule(current, previous /*null when async*/) {
var currencyCode = current.total_app_budget.getCurrencyCode();
var totalBudget = parseFloat(current.total_app_budget.getCurrencyValue());
var totalExpense = parseFloat(current.total_app_expense.getCurrencyValue());
var total = totalBudget + totalExpense;
current.not_to_exceed_amount.setValue(currencyCode + ";" + total.toFixed(2)); // Use toFixed for two decimal places
})(current, previous);
. Thank You for your help @Runjay Patel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2024 07:11 AM
You need it in yaun right? What’s the value showing now?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2024 07:58 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2024 08:48 AM
One of my colleague was able to sort it out for me
(function executeRule(current, previous /*null when async*/) {
var currencyCode = current.total_app_budget.getCurrencyCode();
var totalBudget = parseFloat(current.total_app_budget.getCurrencyValue());
var totalExpense = parseFloat(current.total_app_expense.getCurrencyValue());
var total = totalBudget + totalExpense;
current.not_to_exceed_amount.setValue(currencyCode + ";" + total.toFixed(2)); // Use toFixed for two decimal places
})(current, previous);
. Thank You for your help @Runjay Patel