Script - remove spaces from a variable

Hi All,

In a script I'm trying to use a dynamic string variable to take the script.queue name variable and remove any spaces in the queue name and add it to a new variable for use in a URL.

I've been digging and digging and cannot find how to do this in the script, I know how to do it in architect with Replace() but not in the script.

I tried using some JS stuff like
{{Queue Name}}.replaceAll(/\s/g,'')
just replace()

but can't get it to work.

Original string will be "Customer Voice Queue"
Output string will be "CustomerVoiceQueue"

Thanks for the help

Hello,

I am not an expert in Scripts (I mean I don't practice it often) but I think the only available string manipulation functions are the ones described here: https://help.mypurecloud.com/articles/additional-functions-to-use-in-dynamic-variables/
So probably no easy way to do a replace when not knowing in advance the number of spaces in the string.

You can request new features and share your use case at https://genesyscloud.ideas.aha.io/

Having said that, is there a specific reason why you need to remove the spaces in the variable for a URL?
I mean that if you are opening the URL using "Scripter.Open URL" or if you are displaying it using a Web Page component, the spaces will automatically be replaced with %20.
So it might be easier to manage this in your web app (the one behind the url). Extracting the info from the url (in the url path, or in query parameters), you can easily revert it back to the full Queue name (with spaces).
"Customer Voice Queue" -> https://mysite/Customer%20Voice%20Queue/ or https://mysite?queue=Customer%20Voice%20Queue

Regards,

Hi Jerome,

Thanks for the detail, I knew about the "additional functions to use in dynamic variables page", and didn't see the function in the list there, but I've found undocumented features before that were quite helpful.

The reason behind wanting to remove spaces was for outbound queue calls, we want to add on the queue name to a URL string to determine what webpage to load in the iFrame, but like you say it's probably going to be easier for the web developer to just handle the spaces on their side, there are a lot of queues and they all have spaces in the name which isn't a big deal, was just exploying options.

Thanks for the help,

Kind Regards,

Nathan

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.