Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Use javascript "replace" function in dynamic pdf created with Livecycle designer

Avatar

Level 1

Hi -

I have created a multi-field pdf form that includes a button that generates an email.  The email body contains content of specified fields.  All this is working fine.  The issue is that in one of the fields, a network path is entered.  When the email is generated that information is included in the body of the email and often the resulting link is broken, because the path often contains spaces in the path name.  It seems that i can fix this issue if the empty spaces in the path are replaced by %, for example, prior to having users generate the email.

How do I create a javascript event that looks at the raw value of the field where the network path is stored and replace any blank spaces with a % sign?

Thank you so much in advance for your help!!!!

1 Accepted Solution

Avatar

Correct answer by
Level 7

Here's a screenshot of the example. This is the exit event for tfFieldWithSpaces.

786623_pastedImage_0.png

View solution in original post

6 Replies

Avatar

Level 7

The built-in javascript replace function should work just fine.


tfFieldWithoutSpaces.rawValue = tfFieldWithSpaces.rawValue.replace(/ /g,'%');



But if this is part of a link, do you want %20 instead? That's the URL equivalent of a space.


tfFieldWithoutSpaces.rawValue = tfFieldWithSpaces.rawValue.replace(/ /g,'%20');


Avatar

Level 1

THank so much for the quick reply!

I tried your suggestion but I'm not getting the expected result.  Just to confirm - you say "built-in javascript replace function should work" - but where do I reference that or build it in (sorry )?  I had been trying to run the script on an exit (or change) event of the FieldWithSpaces.  But I am admittedly not experienced in any of this and apparently am still missing something.  Could you more specifically tell me where/how to enter this code?

I'm not seeing any data at all populating in my FieldWithoutSpaces - do I need to set that field a certain way?  And yes, thank you, I do want a space, so I guess I do want '%20'

Avatar

Correct answer by
Level 7

Here's a screenshot of the example. This is the exit event for tfFieldWithSpaces.

786623_pastedImage_0.png

Avatar

Level 1

Thanks so much!!! That seems to work!!!  - at least to replace the characters as requested...now the link is not being understood - so that's the next hurdle - but I appreciate your scripting help!!!!  Any advice on the link appreciated -

Avatar

Level 7

Like I said earlier, a space in a URL or equivalent file path is usually changed to %20 instead of a space. Have you tried using that in the replace function?

Avatar

Level 1

Thank you!!! Your help with the replace option worked perfectly!!!  I was able to replace the spaces with %20 using your code above...at that point I still had an issue because the resulting NETWORK link (vs. hyperlink) was no longer being recognized when it was copied into my auto-generated email (it didn't understand %20)...but I solved that too by adding the'File://' + to the tfFieldWithSpaces exit event:

tfFieldWithNoSpaces.rawValue = 'File://' + this.rawvalue.replace (/ /g, '%20');

And now my auto-generated email contains a link to the network path as needed!

YAY!!!