How to remove white space from a string field in REST API call ?

Jyoti Mehta
Tera Contributor

Hi,

I need a help for removing white spaces from Pending reason (SLA_SUSPENDED_FOR) field before sending it to third party system.

we are using RESTMessageV2 API , sending data to third party system using scheduled job and we have tried setStringParameter but that did not work for white spaces removal. we are using JSON format here. 

can anyone suggest the syntax or how we can remove the white spaces in string field ?

 

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Jyoti,

To remove leading and trailing spaces, use .trim().

https://www.w3schools.com/jsref/jsref_trim_string.asp

If it's necessary to concatenate multiple spaces within a text into one, add the following code. Here, variable "str" is a string representing value of Pending reason.

str = str.replace(/  +/g, ' ');

To remove tabs and new lines also, use the following script instead.

str = str.replace(/\s\s+/g, ' ');

View solution in original post

4 REPLIES 4

Hayo Lubbers
Kilo Sage

You can use a regex to remove all white spaces from your string before sending: .replace(/ /g,'')

 
var str = 'a,b,c blabla       nice white space';
gs.info(str.replace(/ /g,''))​

results in : a,b,cblablanicewhitespace

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Jyoti,

To remove leading and trailing spaces, use .trim().

https://www.w3schools.com/jsref/jsref_trim_string.asp

If it's necessary to concatenate multiple spaces within a text into one, add the following code. Here, variable "str" is a string representing value of Pending reason.

str = str.replace(/  +/g, ' ');

To remove tabs and new lines also, use the following script instead.

str = str.replace(/\s\s+/g, ' ');

Hi Hitoshi,

Thanks for your response! Actually I am new to Integrations and don't know exactly how to get the pending reason field value in Str field. could you please help me ?

Regards,

Jyoti 

Thanks! it worked 🙂