Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How can I replace a series of tags in text?

Avatar

Level 2

I am using LiveCycle Designer 10.4 in the SAP environment to create PDF customer quotes. All data is fed into my layout from the SAP system.

Some of the legal text has variables that are automatically populated by the quoting system. The text is fed into my layout with the variables called out by bracketed tags. My mission is to remove the bracketed tags so they do not display in the output that goes to the customer. For example, in the image below, I want the [V1], [/V1], [V2], and [/V2] to be removed.

sample_tags.gif

I have tried both JavaScript and FormCalc to no avail on the initialize and exit events.

Example code that didn't work is below.

FormCalc

$.rawValue = Replace($.rawValue, "[V1]', "")

This script did not find the tag. And even if it did, I'm not sure how to make it loop and find the next tag.

JavaScript

var textWithTags = data.Page1.sub_QuoteTexts.TPAtext.rawValue;

var textNoTags = textWithTags.replace("[V1]", "");

var textNoTags = textNoTags.replace("[/V1]", "");

var textNoTags = textNoTags.replace("[V2]", "");

var textNoTags = textNoTags.replace("[/V2]", "");

data.Page1.sub_QuoteTexts.TPAtext.rawValue = textNoTags;

This JavaScript did work when I set it up in a little HTML page, but not when I ported it into my layout in Designer.

Any help would be very much appreciated.

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 2

I found the solution via some extended searching in these forums. I had figured there must be a way to loop through a string, removing/replacing multiple values. Here is the FormCalc syntax to do it, placed on the layout ready event.

$.rawValue = Replace( Replace($.rawValue, "[V1]", ""), "[V2]", "")

View solution in original post

2 Replies

Avatar

Correct answer by
Level 2

I found the solution via some extended searching in these forums. I had figured there must be a way to loop through a string, removing/replacing multiple values. Here is the FormCalc syntax to do it, placed on the layout ready event.

$.rawValue = Replace( Replace($.rawValue, "[V1]", ""), "[V2]", "")

Avatar

Level 10

Hi,

you also can use a regular expression to find and replace similar strings.


this.rawValue = this.rawValue.replace(/\[\/?V\d\]/g, "");


There are a few great ressources for creating regular expressions.

http://regex101.com/#javascript

http://www.regexr.com/