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.

Contract Currency Issue

RaviDu
Tera Contributor

Hi Coding Experts,

Need a small help.

I have below fields on contract form

RaviDu_0-1706785248411.png

I have written a client script , where If I select a currency in contract currency field , same currency will appear in below fields

Payment amount

Yearly Cost

Tax Cost

Total Cost

Contract Sum

--------------------------------------

Code 

-----------

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

//Type appropriate comment here, and begin script below

var currencyCode = newValue;
var currency_amount = 0.00;
g_form.setValue('payment_amount', currencyCode + ';' + currency_amount);
g_form.setValue('u_one_time_cost', currencyCode + ';' + currency_amount);
g_form.setValue('yearly_cost', currencyCode + ';' + currency_amount);
g_form.setValue('total_cost', currencyCode + ';' + currency_amount);
g_form.setValue('tax_cost', currencyCode + ';' + currency_amount);
g_form.setValue('u_contract_sum', currencyCode + ';' + currency_amount);


}

--------------------------------------------------

This code works fine for few of the currencies like USD, AUD, DKK, SEK, EUR, AUD and for some currencies it gives below error

 

RaviDu_1-1706785630969.png

Need Help Here

------------------------------------------------------------------------------------------

I tired 2nd option to mitigate this error - This fixes the issue mentioned above, but then it messes "

where If I select a currency in contract currency field , same currency will appear in below fields

Payment amount

Yearly Cost

Tax Cost

Total Cost

Contract Sum

"

Need Help Here

--------------------------------------------------

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
  if (isLoading || newValue === '') {
    return;
  }
 
  // Use g_form.getReference to get additional info about the currency
  g_form.getReference('currency_field_name', function(reference) {
    if (reference) {
      var currencyCode = reference.currency_code;
      var currency_amount = 0.00;
 
g_form.setValue('payment_amount', currencyCode + ';' + currency_amount);
g_form.setValue('u_one_time_cost', currencyCode + ';' + currency_amount);
g_form.setValue('yearly_cost', currencyCode + ';' + currency_amount);
g_form.setValue('total_cost', currencyCode + ';' + currency_amount);
g_form.setValue('tax_cost', currencyCode + ';' + currency_amount);
g_form.setValue('u_contract_sum', currencyCode + ';' + currency_amount);
 
    }
  });
}
--------------------------------------------------------------------

 

0 REPLIES 0