Change the Currency symbol when updating the Currency field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 12:26 AM - edited 09-29-2023 01:09 AM
Hello,
I tried to update the currency symbol should be show in total amount but i wont work. It should be the same currency symbol whether i set Per unit and update in total amount.
Here's the code.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var cc = 'USD';
var cb = g_form.getDecimalValue('u_per_unit');
var ob = g_form.getDecimalValue('u_quantity');
var total = parseFloat(cb)*parseFloat(ob);
g_form.setValue('u_total_amount',cc + ';' + formatNumber(total));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 01:51 AM
Hi @Community Alums ,
It appears you're trying to change the currency symbol based on user input when updating the 'Currency' field. However, your code seems to be adding 'USD' as a static currency symbol regardless of the 'Per unit' value.
If you want the currency symbol to be dynamic based on user input and for the 'Total Amount' field to reflect this change, you can modify your code like this:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var currencyField = g_form.getValue('currency'); // Assuming 'currency' is the field where the user selects the currency
var currencySymbol = ''; // Initialize an empty currency symbol
// Map currency codes to symbols, you can extend this as needed
switch (currencyField) {
case 'USD':
currencySymbol = '$';
break;
case 'EUR':
currencySymbol = '€';
break;
// Add more cases as needed for different currencies
}
var perUnit = g_form.getDecimalValue('u_per_unit');
var quantity = g_form.getDecimalValue('u_quantity');
var total = parseFloat(perUnit) * parseFloat(quantity);
// Set the 'Total Amount' field to display the currency symbol and formatted total
g_form.setValue('u_total_amount', currencySymbol + ' ' + formatNumber(total));
}
Thanks,
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 02:24 AM - edited 09-29-2023 02:29 AM
Hello @Ratnakar7
It shows the same result. Still Total amount cant depend on Per unit currency symbol.