URLencode Body text

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

URLencode Body text

Post by LarsA@normik.dk » Mon Mar 25, 2019 12:18 pm

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: 346
Joined: Tue Mar 03, 2015 2:30 pm
Location: Molndal, Sweden

Re: URLencode Body text

Post by LasseThid » Mon Mar 25, 2019 6:27 pm

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 2020 Fall Edition, Enfocus PitStop Server 2020, Enfocus PDF Review, HP SmartStream 12 & Kodak Prinergy 8.2 with RBA
Offset 72x102, Offset Large Format, Digital Large Format and Digital print.

Malcolm Mackenzie
Member
Posts: 101
Joined: Wed Mar 22, 2017 5:05 pm
Location: London, UK
Contact:

Re: URLencode Body text

Post by Malcolm Mackenzie » 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.
replace.png
replace.png (52.4 KiB) Viewed 5894 times

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

Re: URLencode Body text

Post by LarsA@normik.dk » Tue Mar 26, 2019 11:14 am

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: 7
Joined: Mon Mar 25, 2019 11:15 am

Re: URLencode Body text

Post by LarsA@normik.dk » Tue Mar 26, 2019 1:00 pm

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: 101
Joined: Wed Mar 22, 2017 5:05 pm
Location: London, UK
Contact:

Re: URLencode Body text

Post by Malcolm Mackenzie » Tue Mar 26, 2019 3:19 pm

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 » Tue Mar 26, 2019 8:50 pm

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

If I've helped you and you'd like to say thanks, consider adding me on LinkedIn and leaving me an endorsement or recommendation. It helps a lot!

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

Re: URLencode Body text

Post by LarsA@normik.dk » Thu Mar 28, 2019 10:45 am

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: 7
Joined: Mon Mar 25, 2019 11:15 am

Re: URLencode Body text

Post by LarsA@normik.dk » Thu Mar 28, 2019 12:33 pm

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

Post Reply