Page 1 of 1

URLencode Body text

Posted: Mon Mar 25, 2019 12:18 pm
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

Re: URLencode Body text

Posted: Mon Mar 25, 2019 6:27 pm
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.

Re: URLencode Body text

Posted: Mon Mar 25, 2019 6:39 pm
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 10833 times

Re: URLencode Body text

Posted: Tue Mar 26, 2019 11:14 am
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.

Re: URLencode Body text

Posted: Tue Mar 26, 2019 1:00 pm
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?

Re: URLencode Body text

Posted: Tue Mar 26, 2019 3:19 pm
by Malcolm Mackenzie
Hi Lars

My stupidity for not reading the issue correctly.

Re: URLencode Body text

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

Re: URLencode Body text

Posted: Thu Mar 28, 2019 10:45 am
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

Re: URLencode Body text

Posted: Thu Mar 28, 2019 12:33 pm
by LarsA@normik.dk
Installed the Scriting Module trail, and Gabriel's solution worked great :D
Thanks again.