Blog

Remove Commas from a String Field

Ever do an import into ServiceNow with Excel and the string field you intended to be an id field has commas imported into it?

Here is the comma eliminator you are looking for.  

Remember to run in a development instance and test before running in production ServiceNow instance.

1. Elevate your privilege to security_admin.
2. In the Left Navigator > Scripts - Background
3. Paste this in the Run Scripts area. 

//Replace 'table name here','query here if needed','field name here' ith your parameters for the comma remove
removeCommas('table name here','query here if needed','field name here');
function removeCommas(rcTableName,rcEncodedQuery,rcFieldName) {
 var grCommaRemove = new GlideRecord(rcTableName);
 grCommaRemove.addEncodedQuery(rcEncodedQuery)
 grCommaRemove.query();
 var updateCount = 0;
 while(grCommaRemove.next()){
 grCommaRemove[rcFieldName] = grCommaRemove[rcFieldName].replace(/,/g , "");
 grCommaRemove.update();
 updateCount++;
 }
 gs.print('Records Updated: '+ updateCount);
}

4. Click Run Script