Avoid spaces in a sum function when a variable is empty/void
Hello, the product name in my products database is a sum of 9 text and number fields, like this
article + " " + Color + " " + more stuffs + " " +kg + " " lt"
it works for normal use but in print view, when a field is empty, it still leaves the space (of course), like this:
article color lt
I can't remove the space from the function or i end up like this
articlecolorlt
Is there a better way/funciton instead of sum to avoid this? I would like that when a field is empty/void it just writes nothing. How? Thanks
8 replies
-
I'm sure there is a way to figure out how not to put in empty fields, but here is a regex way of doing it.
You can create a formula field and put this in:
replacex(originalformulafield, "\s{2,}", " ")
This will find all instance of two or more spaces and replace it with a single space.
-
Hi Lorenzo
If you create an array of the field values you can then use concat to create a string, and replace to remove the commas.
let a := [article,Color,more stuff,kg,lt]; let b := concat(a); let c := replace(b,",","")
I thought you could use the join function but this does not remove empty array elements where concat does.
This still isn't ideal, as any commas within your fields will also be removed.
Regards John
-
A better solution is
let a := [article,Color,more stuff,kg,lt]; let b:= a[let c := this; length(c) > 1]; let d := join(b," ")
Regards John
-
Or even simpler:
let a := [article,Color,more stuff,kg,lt]; let b:= join(a[!=""]," ")
-
Or maybe a oneliner ?
Article + if Color then " " + Color end + if 'More stufs' then " " + 'More stufs' end + if Kg then " " + Kg end + if Lt then " " + Lt end
-
Love the community engagement.
By the way you can also take my suggestion and add it to your original code. :)
let x := original code; replacex(x, "\s{2,}", " ")
-
Thanks everyone, I appreciated all of your answers and the different solutions you came up with. Awesome community!
Content aside
- Status Answered
-
1
Likes
- 1 yr agoLast active
- 8Replies
- 146Views
-
5
Following