- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Extra spaces are clearly one of those nightmares of the IT world that continually haunt end users as well as admins and developers. While surfing the web, have you ever come across ugly hyperlinks with underlining stretching beyond the link text? Or have you ever been unable to log in to an application because you overlooked a trailing space when copying the password from an email? Or maybe you happened to waste a few hours debugging your app because of an extra whitespace character in the value of a string variable that went unnoticed?
Now that these examples have hopefully evoked some reminiscences, let us get down to the business of banishing unwanted spaces from your ServiceNow instances. It goes without saying that the golden rule for any development is of course to cleanse the data before putting it into the database. In ServiceNow, this is easily achievable through a before business rule:
current.field_name = current.field_name.trim();
It takes almost no time to create a rule that can save you hours of troubleshooting headache later on!
Preventive measures are never a bad thing but the question you are likely to ask is: "What if I wanted to check if extra spaces have already found their way into my ServiceNow instance?"
Indeed one cannot search for a whitespace character using list search in a regular way because — as you would naturally expect — ServiceNow follows the aforementioned golden rule and trims the input before executing the search. So in this case — strange as it may sound — we will have to work around a best practice. Luckily list search supports the use of JavaScript. Thus if you wanted to find all records in a table with a trailing space in, say, Name field, you could simply select that field in the Go to box and search for:
%javascript:' ';
Note the usage of the % character as a wildcard in this example. Alternatively you could build the following condition in the list filter to achieve the same result:
Name — ends with — javascript:' ';
As you can see, the trick is very simple and leaves no space for undesired spaces in your ServiceNow instance. Moreover, the same technique can be used to find records with leading spaces or characters that have a special meaning for the search engine:
%javascript:'*'; // find trailing asterisks
*javascript:'%'; // find records with % characters
- 4,828 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
