Converting newValue to uppercase

MWright1
Giga Guru

I have a Service Catalog item with an input field.

 

I have Client script that I run onChange of this input field that checks input value.  In order to avoid case mis-types, I am trying to convert the input value into uppercase and then checking only the uppercase of the value:

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var val = newValue.toUppercase();  // I have also tried:  var val = newValue.toString().toUppercase();
    if (val == 'MYTEST'){
        // do something here
        alert(val);
    }
}

 

 
I keep getting a javascript error on the "var val" line.  Any idea how else I can convert the value to uppercase?
 
Thanks.

 

2 REPLIES 2

_Gaurav
Kilo Sage

Hi @MWright1 
If you try the below code, it will give you all the characters in uppercase in your CS

 

var str = newValue.toUpperCase();
alert(str);
 
Please mark this as a solution and helpful if this resolves your query
Thanks!

Ankur Bawiskar
Tera Patron
Tera Patron

@MWright1 

you are using wrong method name -> correct method is toUpperCase()

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var val = newValue.toUpperCase();  // Correct method name
    if (val == 'MYTEST') {
        // do something here
        alert(val);
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader