Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Get Currency Value in Client Script

keesh
Mega Contributor

Hello Community,

I have a client script for the Requested Item table that sets currency to CAD if the user's country is Canada. The functionality works as required, however I need some assistance with adding the following logic to my script:

If user's country = CA and the 'price' field = 0.00 

Client Script:

function onLoad() {
// Get Current User
var user = new GlideRecord("sys_user");
if (user.get(g_user.userID)) {
// If Canadian, set currency to CAD
if (user.country == 'CA' && g_form.getValue('price') == 'USD;0.00') {
g_form.setValue('price.currency', 'CAD');
}
}
}

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Here you go

 

function onLoad() {
// Get Current User
var user = new GlideRecord("sys_user");
user.addQuery("sys_id",g_user.userID);
user.query();
if(user.next()){
// If Canadian, set currency to CAD
if (user.country == 'CA' && g_form.getValue('price') == 'USD;0.00') {
g_form.setValue('price.currency', 'CAD');
}
}
}

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron

Hi Keesh,

The code seems fine. just test it once and check if it is working fine.

g_form.getValue('price') == 'USD;0.00' looks fine

But not sure whether you can set CAN for canada

Check this should help:

https://community.servicenow.com/community?id=community_blog&sys_id=583eaa6ddbd0dbc01dcaf3231f9619fa

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Abhinay Erra
Giga Sage

Here you go

 

function onLoad() {
// Get Current User
var user = new GlideRecord("sys_user");
user.addQuery("sys_id",g_user.userID);
user.query();
if(user.next()){
// If Canadian, set currency to CAD
if (user.country == 'CA' && g_form.getValue('price') == 'USD;0.00') {
g_form.setValue('price.currency', 'CAD');
}
}
}

Thank you abhinay 🙂

you bet!