- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2016 10:30 AM
Hello all!
Hope you are having a great Monday. I have a scripting question, might be simple but I'm not very good with Regular Expressions. Any help is appreciated.
So I have this string field, say 'Summary' and I'm storing the values of 8 other fields appended to one another into this field. There are 4 fields which might have 'none' as an option. So, when I print this 'Summary' and if any of the fields have 'none' as an option or if one of the string fields is left empty, 'Summary' shows 'null' in its place. I don't want this. If it's just one field, I would write an if-else condition to check if null and print accordingly. But since it's 4 fields an any no. of fields can be left empty, there's just too many conditions to consider.
So I came up with this solution. I'm appending every field value into 'Summary' and then check it's contents for the word 'null' and replace every occurrence with a space or something that results in removing it from the string. This is the Regular expression I came up with (not sure if it's right) -> (^|\s)null(?=\s|$)
But I'm not sure how to iterate through the string and remove every occurrence. Please help!!! Thanks in advance.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2016 11:11 AM
I got it!
var regex = '(^|\s)null(?=\s|$)';
summary = summary.replace(/null/gi, '');
This removed every occurrence of null from the variable summary. The rest is pretty straightforward (setting the value in the field)
Thanks Abhinay for trying to help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2016 10:33 AM
When you say summary, are you talking about email notification?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2016 10:54 AM
No Abhinay. It's just a string field in another table. It displays the concatenated string formed by appending multiple other string fields.
All that other functionalities are achieved, so no question about that. I only need to know how to remove all occurrences of 'null' in a string field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2016 11:11 AM
I got it!
var regex = '(^|\s)null(?=\s|$)';
summary = summary.replace(/null/gi, '');
This removed every occurrence of null from the variable summary. The rest is pretty straightforward (setting the value in the field)
Thanks Abhinay for trying to help.