URLencode Body text

Post Reply
LarsA@normik.dk
Newbie
Posts: 9
Joined: Mon Mar 25, 2019 11:15 am

URLencode Body text

Post by LarsA@normik.dk »

Hi,

Is there a way to replace spaces in folder names, in an url send in mail Body text?

Data:
file:///Volumes/Switch/[Job:UserFullName]/[Metadata.Text:Path="/field-list/field[1]/value",Dataset="Submit",Model="XML"]/[Job.Name]

Output
file:///Volumes/Switch/John A Smith/Folder 1 A/file1.pdf
Desired Output
file:///Volumes/Switch/John%20A%20Smith/Folder%201%20A/file1.pdf

Regards
Lars
LasseThid
Advanced member
Posts: 353
Joined: Tue Mar 03, 2015 2:30 pm
Location: Molndal, Sweden

Re: URLencode Body text

Post by LasseThid »

I don't know how to replace the spaces with %20, but I'd like to give you a tip regarding the metadata path.
If you want to increase readability and make it easier to know what metadata you're actually picking up, you can change the statement from:

[Metadata.Text:Path="/field-list/field[1]/value",Dataset="Submit",Model="XML"]

to

[Metadata.Text:Path="//field[tag='tag name']/value",Dataset="Submit",Model="XML"]

Where tag name is the metadata tag you're looking for. In you case it might be folderName, which would give you [Metadata.Text:Path="//field[tag='folderName']/value",Dataset="Submit",Model="XML"].
This is espescially helpful if you have a long metadata path. I've had paths like [Metadata.Text:Path="/field-list/field[1]/field-list/field[1]/field-list/field[2]/value",Dataset="Submit",Model="XML"] that I've been able to change to [Metadata.Text:Path="//field[tag='CSR E-mail']/value",Dataset="Submit",Model="XML"].

The tag name can be found in the metadata when you build your path in Switch.
Enfocus Switch, Enfocus PitStop Server, Enfocus PDF Review, HP SmartStream& Kodak Prinergy with RBA
Offset 72x102, Offset Large Format, Digital Large Format and Digital print.
Malcolm Mackenzie
Member
Posts: 121
Joined: Wed Mar 22, 2017 5:05 pm
Location: London, UK
Contact:

Re: URLencode Body text

Post by Malcolm Mackenzie »

Hi
If you do rename and set it to search for Inline Value and it really is a space on the space bar.
Sort of like below (should be %20) it should work.
replace.png
replace.png (52.4 KiB) Viewed 10821 times
LarsA@normik.dk
Newbie
Posts: 9
Joined: Mon Mar 25, 2019 11:15 am

Re: URLencode Body text

Post by LarsA@normik.dk »

LasseThid wrote: Mon Mar 25, 2019 6:27 pm If you want to increase readability and make it easier to know what metadata you're actually picking up, you can change the statement from:
[Metadata.Text:Path="/field-list/field[1]/value",Dataset="Submit",Model="XML"]
to
[Metadata.Text:Path="//field[tag='tag name']/value",Dataset="Submit",Model="XML"]
Thanks Lasse,
That's good advice.
LarsA@normik.dk
Newbie
Posts: 9
Joined: Mon Mar 25, 2019 11:15 am

Re: URLencode Body text

Post by LarsA@normik.dk »

Malcolm Mackenzie wrote: Mon Mar 25, 2019 6:39 pm Hi
If you do rename and set it to search for Inline Value and it really is a space on the space bar.
Sort of like below (should be %20) it should work.
Hi Malcom,
Not sure that you can use Rename to modify metadata values?
Malcolm Mackenzie
Member
Posts: 121
Joined: Wed Mar 22, 2017 5:05 pm
Location: London, UK
Contact:

Re: URLencode Body text

Post by Malcolm Mackenzie »

Hi Lars

My stupidity for not reading the issue correctly.
User avatar
gabrielp
Advanced member
Posts: 645
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: URLencode Body text

Post by gabrielp »

I haven't used Switch in a while -- so take this comment with a grain of salt.

The easiest (laziest?) way I can think of would be to remove any characters that need to be encoded. You could do that with a little regex or use a script like this (which will do that for you) https://github.com/open-automation/swit ... e-scrubber But if you are targeting a file on a volume then you would need to address the issue upstream from where you are referencing it.

But if you decide to write a script to do url encoding, maybe take a look at the script above which does a regex replace. You could tweak the same technique to replace the other characters or use the encodeURI method of the HTTP class https://www.enfocus.com/manuals/Develop ... class.html
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore

Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
LarsA@normik.dk
Newbie
Posts: 9
Joined: Mon Mar 25, 2019 11:15 am

Re: URLencode Body text

Post by LarsA@normik.dk »

gabrielp wrote: Tue Mar 26, 2019 8:50 pm ... or use a script like this (which will do that for you) https://github.com/open-automation/swit ... e-scrubber.
Thanks Gabriel,
This looks like the right solution, but I will need the Scriting Module for this, right?

Image
LarsA@normik.dk
Newbie
Posts: 9
Joined: Mon Mar 25, 2019 11:15 am

Re: URLencode Body text

Post by LarsA@normik.dk »

Installed the Scriting Module trail, and Gabriel's solution worked great :D
Thanks again.
Post Reply