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.

Removing special characters Dynamically

dpi
Kilo Contributor

Hi All ,

can you please help me on the below :

As a past of integration , i need to remove special symbols DYNAMICALLY (Chinese/some strange symbols) in the description (XML not accepting these symbols) . i tried like below but not getting how to push the unwanted value in to another Array. below is the onchange client script on a filed , can some one please help me   in achieving this . Thank you

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue == '') {

          return;

    }

*****

    //Type appropriate comment here, and begin script below

  if ( newValue == 'XXXX' || 'YYYY' || 'ZZZZ')

  {

  alert("hello");

  var val = [];

  val = g_form.getValue('description');  

  alert(val);

  var achar =[];

        achar = 'abcdefghijklmnop'; //need to add 26 alphabets here

  var k=0;

  var result;

  var i;

  var array = [];

  var answer =[];

  var array1 = val.toLowerCase().split('');  

              for ( i=0; i <=val.length; i++){  

  {

  //alert("first forloop");

  for (var j=0; j <=achar.length; j++)

  {

  if(val[i] != achar[j]) // up to this point processor works tried with some alerts , here not working

  {

  array.push(val[i]);

  k++;

  }

          }

                      }

                                      }

                                                }

                                                          }

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Here is how you can remove the special characters



var new_desc=g_form.getValue('description').toString().replace(/[^a-zA-Z ]/g, "");


View solution in original post

3 REPLIES 3

Abhinay Erra
Giga Sage

Here is how you can remove the special characters



var new_desc=g_form.getValue('description').toString().replace(/[^a-zA-Z ]/g, "");


Rakesh Mamidi
ServiceNow Employee
ServiceNow Employee

Include alphanumeric and only replace special characters.


var new_desc=g_form.getValue('description').toString().replace(/[^a-zA-Z0-9]/g, '');


Hi Abinay/Rakesh ,



Thanks for your prompt response, the proposed solution is working now . Thanks again