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

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');

 

 

I like this solution, it is much simpler....however, I can't make it work on change. Users might click save/update and not see the message...

 

This instruction is mentioned under the UI policy form: "Apply the UI policy actions when the form is loaded and when the user changes values on the form".

 

It is not really working "onChange", though..

Hi Samuel, 

You could add below code, just before the code I provided to clear the value entered by user whenever condition is not being satisfied. Then you could achieve your goal I think.

g_form.clearValue('currency');

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

This instruction is mentioned under the UI policy form: "Apply the UI policy actions when the form is loaded and when the user changes values on the form".

 

It is not really working "onChange", though..

sanjayh64910723
Tera Contributor

Please try below code : 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
  if (isLoading || newValue === "") {
    return;
  }
  var finalCost;

  if (newValue && newValue !== oldValue) {
    finalCost = newValue.replaceAll(",", "");

    finalCost = finalCost.split(";")[1];
    finalCost = parseFloat(finalCost);

    // If final cost is less than threshold, show info message
    if (finalCost < 10000) {
      g_form.addInfoMessage("Cost is less than 100,000");
    }
  }
}