Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Find and replace macro

Avatar

Former Community Member

Hello!

Reading around I found out it is possible to create macros in LC Designer and placing them under the Tools menu (http://blogs.adobe.com/formfeed/2010/01/designer_es2_macros.html).

However, what I need is something hopefuly simpler: I need a script to find and replace certain characters in the form text, such as replacing % with ç, globaly.

Where do I find simple examples of how to do this?

Thank you for any ideas!

Marcos

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

the macro doesn't touch any tooltips right now as they are not stored in "value" nodes.

As I mentioned you should not use any special characters (means all characters that are not used in the US) in the whole macro.

So if you try to replace all ç use var RegEx = /\u00E7/gm.

View solution in original post

14 Replies

Avatar

Level 10

Do you want do replace the characters during runtime (Acrobat/Reader) or at design time (Designer)?

Macros are only usable at design time.

They can do a lot a things, but it you need to develop them yourself.

To replace special characters and string you also can switch to the xml source and press ctrl+H.

During runtime you can use scripts with regular expressions to replace strings etc.

Avatar

Former Community Member

Hello Radzmar!

Thank you very much for your reply!

Actually I need this done at design time. Yes, I know I will have to develop it myself, I'm just a bit lost as to where to start.

Reason for all this: client upgraded 2,400 forms from old times JetForms and a great number of Portuguese special characters did not translate correctly, the result is a mess.

We have even contacted Adobe Support but they did not find a solution for this problem.

So I was left with the task of correcting this... The initial approach was to save the forms as XDP and apply the corrections using a script we did in Acrobat. It works, but it turned down that when we save as XDP the checkboxes and radio buttons are all messed up!

A very alternative way was to do some copy and pasting, using the original XML code - it works, but the client is not happy with so much work for 2,400 forms...

So I thought about creating a macro in LiveCycle Designer. I implemented the sample from the URL I mentioned above, but that's not what I need and I do not have (yet) enough knowledge of scripting in this environment to create my own.

Thank you!

Best Regards,

Marcos

Avatar

Level 10

Ok,

where are those characters in your forms?

In static texts or in captions or field values etc.

Can you share one of the forms, so I can check how to fix it with a macro?

Avatar

Former Community Member

Hello Radzmar!

Thank you very much!

The characters are in static texts, captions, etc. Curiously enough, they translate correctly in tooltips.

Yes, of course I can share a sample. Where do I send it to, please? I did not see any attachment option in this forum.

Thank you!!

Marcos

Avatar

Level 10

Hi,

here's a macro for your task.

It looks for all nodes with a "value" class and replaces all % with ç.

This solution is hard coded, so if you need more to replace other characters you have to change the regular expression and the replace function.

Pay attention with special characters (umlauts etc.) in the macro, they can cause the script to fail.

For example: .replace(RegEx, "ç"); doesn't work.

Use the unicode notation instead, then it generally works.

Avatar

Former Community Member

Hi Radzmar!

Thank you so much for your script! I've tested and it works great.

Now, I still have some questions...

1. If the character to be replaced is, say, a "ç", must I use the unicode equivalent in the regular expression?

2. Curiously enough, special characters located inside the <tooltip></tooltip> tags are translated correctly and should not be touched by the scrtpt. How do I test for these tags to leave them unchanged?

Thank you again!

Marcos

Avatar

Correct answer by
Level 10

Hi,

the macro doesn't touch any tooltips right now as they are not stored in "value" nodes.

As I mentioned you should not use any special characters (means all characters that are not used in the US) in the whole macro.

So if you try to replace all ç use var RegEx = /\u00E7/gm.

Avatar

Former Community Member

Hi Radzmar!

Great!

I think this will solve the issue.

Now, something strange is happening - the script was working just fine until yesterday...

Now, when I try to run it, I get this error message:

"Error: Invalid property get operation; line doesn't have property 'value'"

Any idea of why this is happening?

Thank you very much once again!

Marcos

Avatar

Level 10

How does you script looks like?

Have you done any changes to it? The error indicates that you trying to change the value property of a line object, which generally doesn't have that property.

Avatar

Former Community Member

No, I haven't changed your script!

I just tried to run it to correct one of the client's forms.

It still works if I create a new blank form, create a field and run the script.

Marcos

Avatar

Level 10

Ok,

if found the reason.

We have to exclude some classNames which cannot be changed.

Avatar

Former Community Member

Thank you again!  :)

But we still have problems...

Runs ok with a new blank form with one field.

With one of the client's forms, brings up the error message:

"Error: oldValue.replace is not a function".

Marcos

Avatar

Level 10

Ok,

I see the problem.

This happens when the returned value is null.

Next try:

Avatar

Former Community Member

Aha!

Now it's working beautifully.

Thank you very much!!!

All the best!

Marcos