Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

It is a bery bad practice use GlideRecord in Client side scripts