logo

NJP

Currency variable in the Service Portal

Import · Jul 24, 2019 · article

Here's a nice simple solution to the challenge of allowing multiple currencies in the Service Portal

image

First, set up a couple of fields...

  • Currency -- reference -- fx_currency -- add a default value
  • Amount -- string

If you'd like your currency to include the name of the currency and not just the three letter abbreviation, add the following to the currency's variable attribute

  • ref_auto_completer=AJAXTableCompleter,ref_ac_columns_search=true,ref_ac_columns=name

Next, if you'd like the amount field to right-align and have some simple validation, add the following catalog client scripts

Right-align amount field (on load)

function onLoad() {

    this.setTimeout(function(){ 
        this.jQuery('#sp_formfield_amount').css('text-align','right'); 
        this.jQuery('#sp_formfield_amount').attr("placeholder", "As an example... $10,000.00");
    }, 350);

}

Ensure only numeric values (amount on change)

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

    newValue = newValue.split(',').join('');
    newValue = newValue.split('$').join('');
    if(!parseInt(newValue)){
        g_form.addErrorMessage('You must enter a numeric value: '+ newValue + ' cannot be resolved as an amount');
        g_form.setValue('amount','');
    }

}

Then at the back end, in your record producer script, simply combine these two fields into your currency field

current.u_estimated_contract_value.setValue(producer.currency + ";" + producer.amount);

You'll also need an ACL to allow users to see the fx_currency table

image

Then in the back end of ServiceNow you'll see the result from your service portal form

image

Have fun

View original source

https://www.servicenow.com/community/now-platform-articles/currency-variable-in-the-service-portal/ta-p/2310788