Script to remove all spaces in a string is not working within Integration HUb

jonathangilbert
Mega Sage

Morning All

 

I have an issue with a script that I am using to set a flow variable within Integration Hub. I require the script to remove ALL spaces in a text string, but it does not work.

 

Here is my script:-

 

var first = fd_data.subflow_inputs.first_name.toLowerCase();
var first2 = first.replace(" ", "");
return first2;
 
 
I have tried to use replaceALL(" ", "");
 
I am trying to cover all formats of a persons first name  for example:-
 
John Paul (space between the name
John - Paul (space then a hyphen then another space)
 
If I use my current script it will remove the first space, but not the second, so the result is "john- paul", 
 
If I use replaceALL, the script comes back as nAn. Any ideas?. I require it to remove all spaces so that I can automate creating users with emails in Entra
 
Thankyou in advance
1 ACCEPTED SOLUTION

Anand__99
Mega Sage

Hi @jonathangilbert ,

 

It's not replaceALL (javascript is case-sensitive), use replaceAll(" ","")

 

Thanks

Anand

View solution in original post

4 REPLIES 4

Anand__99
Mega Sage

Hi @jonathangilbert ,

 

It's not replaceALL (javascript is case-sensitive), use replaceAll(" ","")

 

Thanks

Anand

TharaS657398130
Tera Guru

Hello

Since you want to remove ALL spaces, including multiple spaces around hyphens, use a regular expression

 

var first = fd_data.subflow_inputs.first_name.toLowerCase();
var first2 = first.replace(/\s/g, "");
return first2;

Juhi Poddar
Kilo Patron

Hello @jonathangilbert 

You can try either of these two approaches:

1. Use replaceAll()
JavaScript is case-sensitive, so replaceALL() is not a valid method. The correct method is replaceAll() with a lowercase l:

name.replaceAll(" ", "");

2. Use a regular expression

You can also use a regex with the global (g) flag to remove all whitespace:

name.replace(/\s/g, "");

 Hope this helps!

 

Thank You!

Juhi Poddar

Thank You!
Juhi Poddar

jonathangilbert
Mega Sage

Thank you so much Anand, that worked. I only used ALL as that is what I had seen in a Google search result