OnChange client script on Currency field

peterg157
Kilo Contributor

Hi Friends,

We have a requirement, where we need to hide/visible a field based on a amount field(Field type is currency). For example, if the amount is less than 10K, fields need to visible, otherwise field should not visible.

For this we tried to do using UI policy and Client script. But during the form Load , it's working fine. But it's not working , during field value Change.

Please provide your inputs.

Thanks.

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Use this script



if(parseFloat(newValue.split(';')[1])<10000){


  g_form.setDisplay('field_name',true);


}


else{


  g_form.setDisplay('field_name',false);


}


View solution in original post

20 REPLIES 20

Abhinay Erra
Giga Sage

Use this script



if(parseFloat(newValue.split(';')[1])<10000){


  g_form.setDisplay('field_name',true);


}


else{


  g_form.setDisplay('field_name',false);


}


Thank you Abhinay for the reply.



We tried this one in client script. But script is not working if we, change field value. It's working on form load.


Keep in mind that parseFloat will not work properly for localized instances



For example in Germany


  • "," is used as decimal seperator
  • and "." is used as thousand seperator.


Now lets have this example field


  • Field "cost" has set EUR 10.000,50


Here


  • g_form.getValue("cost") will return EUR;20.000,50
  • parseInt(g_form.getValue("cost_field").split(";")[1] < 10000 would now be true because parse "COST" is interpreted as 20 Euros instead of 20000 Euros and 50 Cents


However you can use g_form.getIntValue to get the Integer   At least it seems like this Method is already taking care of the decimal / thousand session seperator. At least I tested getIntValue on 20.000 was in fact returning 20000 on my localiszed instance. But this method has another withdraw, as it will always cut the cents


Abhinay Erra
Giga Sage

Where did you place this script? Can you post the script you are using?