Delete whitespaces from a String using Smart Value

Parvaneh Zand
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 13, 2020

Hi everyone,

I want to get a String without whitespaces using smart values (in Project Automation), which copies values of a Multi-user picker field into a single-line text field.

By simply using {{issue.myField}}, It puts white spaces between usernames:

usernameA, usernameB, usernameC

I've tried :

{{issue.myField.remove("")}}

and

{{issue.myField.deleteWhitespace()}}

but all characters were deleted!

Do you know how I can remove those spaces?

Thanks.

5 answers

2 votes
Aaron P.
Contributor
March 28, 2023

Hi everybody,
Thanks by this solution, this helped me a lot.
But, I can use it .replace(" ", "")}} more than once?
For example:
{{Name.replace(" ", "") ("á", "a") ("é", "e")}} etc
In my work use the name of employe for create the email and need replace the characters with accents and umlaut or specials (ñ, ç).

Aaron P.
Contributor
September 21, 2023

ok, the correct syntax is reiterate the function for each case:

{{Name.replace(" ", "").replace("á", "a").replace("é", "e")}}

David Vermeir October 20, 2023

Couldn't get it to work. I have a field `issue.Domain` but when I create a variable (Smart Value) called DomainLabel with {{issue.Domain.replace(" ", "")}} it just returns an empty string.

Aaron P.
Contributor
October 23, 2023

Hi David,
Is possible that atlassian not recognize the name of your field, trial use with this sintax:

{{issue.customfield_XXX.replace(" ", "")}}
Wherein XXX is the ID of the field. This ID you can see in the URL of setting of the field, in the image is the las number.

 

screenshot_1035.png

David Vermeir October 24, 2023

Hi Aaron,

 

doesn't work either. For full context, the custom field is a list of which only one option can be selected (only text values). What I'm trying to do is use a web request automation rule that labels a linked Confluence page with the "Domain" value of the issue. Domain values can have spaces however, so I want to replace the spaces with "-" so Confluence doesn't create a label per word in the selected Domain value.

API: https://<tenant>.atlassian.net/wiki/rest/api/content/{{createdPage.id}}/label

Method: POST

Body:

[
{
"prefix": "global",
"name": "project-overview"
},
{
"prefix": "global",
"name": "{{issue.Domain.replace(" ", "-")}}"
}
]

I thought the double quotes inside the replace function are causing issues with escaping, but when I copy the code to a Create Variable automation component the behaviour is the same. It just returns "".

Aaron P.
Contributor
October 25, 2023

Hi David
If you use a select field, you need add ".value" in the syntax for indicate that use this, in your case:

{{issue.Domain.value.replace(" ", "-")}}

 

Like David Vermeir likes this
David Vermeir October 26, 2023

Awesome, that works! Thx!

Aaron P.
Contributor
October 26, 2023

you are welcome

Eshita Seelam October 22, 2024

Hello @Aaron P. , we tried the {{issue.customfield_XXX.replace(" ", "-")}} while editing another custom field to replace the spaces in between with a hyphen, however it wouldn't recognize this as a smart value, and it wouldn't add the value. Could you help suggest on this.

0 votes
Renan Gomes
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 11, 2022

This can solve your problem:

 

{{yourfield.replace(" ", "")}}
Eshita Seelam October 22, 2024

Hello @Renan Gomes , we tried the {{issue.customfield_XXX.replace(" ", "-")}} while editing another custom field to replace the spaces in between with a hyphen, however it wouldn't recognize this as a smart value, and it wouldn't add the value. Could you help suggest on this.

0 votes
Rory Standley April 28, 2022

I've not tested this but I am pretty sure all you need to do is

 

{{issue.myField.trim()}}
0 votes
Zubair Khan February 23, 2022

Hi @Parvaneh Zand 

 

Have you fixed this issue? Please share possible solution.

 

Thanks 

0 votes
Thomas DeToledo
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 11, 2021

I am not sure you still need it but I was facing the same issue and I found a workaround.

Use the Create Variable component to create the smart value without the space (using remove or Replace function)

Screenshot 2021-05-11 at 13.12.48.png

 

For some reason, the Edit issue field component did not work for me each time I tried to type the character space. But editing inside the create Variable component worked perfectly.

You can then use those smart variables inside the Edit Issue Field component.

Suggest an answer

Log in or Sign up to answer