Change currency code of a field via script

Berati Sahin
Tera Contributor

Hi everyone, 

There are two currency fields. The first of them is Original Cost and the second one is Converted Cost. I want to copy the value of the first currency field, and then I want to paste the value to the second currency field. The value of the first currency field will be passed to the second currency field. I can pass the amount but I cannot change the currency code. In the Orlando release, there are several APIs for currency, but I could not them effectively. How can I set the currency code of the Converted Cost field as the Original Cost? I want to indicate that, when I update the form, the currency code of the Converted Cost field becomes "$" for a short period initially. Then it returns to again "₺".

Besides, I used these two fields for test. If I success to pass amount and currency code from original cost field to converted cost field, I will use these script in the Opportunities module.

Thank you in advance

Have a nice day 🙂

find_real_file.png

 

find_real_file.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you will have to convert USD to your another currency

after you get the converted value you need to set it like this

var currencyCode = 'EUR';

current.u_c_c.setValue(currencyCode + ";" + convertedValue);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you will have to convert USD to your another currency

after you get the converted value you need to set it like this

var currencyCode = 'EUR';

current.u_c_c.setValue(currencyCode + ";" + convertedValue);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank you Sir Ankur,

It works properly. You are the legend 🙂

 

asifnoor
Kilo Patron

Hi,

you can set the currency like this.

current.setValue("your_field",'USD;10'); //separator is ;

Hi Asifnoor,

 

I tried your script with a small modification and it worked. Thank you 🙂

var a='USD;'+amount;
current.setValue("u_c_c",a);