How do I get the currency value of a currency field on a client side script?

samuelscott
Tera Expert

I need to compare a currency value field on a client side script. If the currency field value is less than 10,000 than an info message appears. How do I access the integer value of the currency field? The server side equivalent is "getCurrencyValue", I don't what to do client side though. Also, "onChange script error: ReferenceError: u_final_offer is not defined function () { [native code] }" is an errorI'm getting when executing my client script.

 

Please help.

1 ACCEPTED SOLUTION

Alp Utku
Mega Sage

I would suggest you to write UI policy on curreny field rather than writing client script directly. 

Condition : currency is between 0 and 10000

Then go to the script tab select "Run Scripts" and the code below

g_form.showFieldMsg('currency','Your message here','error');

 

 

View solution in original post

9 REPLIES 9

Mike Patel
Tera Sage

1st lets do alert and see what value you are getting like 

alert(g_form.getValue(u_final_offer)); 

if you are getting like 1000 than you can compare it like

if(g_form.getValue(u_final_offer) <= '10000'){

//do something

}

if you are getting something like USD;0.00 than you can do something like

if(g_form.getValue(u_final_offer) <= 'USD;10,000.00'){

//do something

}

MrMuhammad
Giga Sage

As far as I know we don't have client side function to get currency value. Try this to extract integer value from currency field.

var finalOffer = g_form.getValue('u_final_offer');
var finalOfferStr = finalOffer.split(';')[1];	
var finalOfferInt = parseInt(finalOfferStr);

if(finalOfferInt >= 10000) { 
   //logic here

}

 

Regards,
Muhammad

This script is cutting out only the first comma from the currency value. So for example if I type 31,000,000 the output is 31.

The Script is basically splitting the value based on semi-colon. it strange that its cutting the value based off comma. Did you checked what exact value are you getting from u_final_offer field?

Regards,
Muhammad