cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Replace function from dataitem text to collection

MadalinaAcsinte
Level 3
Hello,

I have a dataitem where I store HTML text from a file. When I get that file into the dataitem, I want to replace some fields with data from a collection instead of plain text. I tried using calculation stage, but I don't know how the function should be.

I tried this function but it didn't work:

Repace([Collection.Field1]], [Collection.Field1])

I also used this text: "[Collection.Field1]" into the HTML file. Now I want to replace that "[Collection.Field1]" text with [Collection.Field1] collection.

Can you give me any ideas?

------------------------------
Madalina Acsinte
------------------------------
1 BEST ANSWER

Helpful Answers

The first argument to put into the Replace function is the name of the data item that contains all the HTML. If your HTML text is in a data item called [HTML text], then the Replace function should look like this:
Replace([HTML text], "[Collection.Name]", [Collection.Name])

------------------------------
Dave Morris
Cano Ai
Atlanta, GA
------------------------------

Dave Morris, 3Ci at Southern Company

View answer in original post

4 REPLIES 4

david.l.morris
Level 15
Could you show an example of the HTML? You may know this already, but here are some examples of how the Replace Function works and maybe this will help:

Example 1:
  • Value in [Text]:
    • This is an example sentence.
  • Expression using Replace:
    • Replace([Text], "sentence", "word")
  • Result:
    • This is an example word.
Example 2:
  • Value in [Text]:
    • <p>My HTML paragraph.</p>
  • Expression using Replace:
    • Replace([Text], "p", "h1")
  • Result:
    • <h1>My HTML paragraph.</h1>

As far as using Collections, it's the same thing except it may involve needing to loop. If you can show an example of what your input is and what your expected output is, then I think we can help, but I don't totally understand what the input/output looks like.

------------------------------
Dave Morris
Cano Ai
Atlanta, GA
------------------------------

Dave Morris, 3Ci at Southern Company

Hi Dave,

Thank you for your answer.

This an example of the HTML text that I want to replace:

<p class=MsoNormal align=center style='text-align:center'><b><span
style='color:black;mso-color-alt:windowtext'>[Collection.Name]</span><o:p></o:p></b></p>

The [Collection.Name] that is stored in a dataitem I want to replace it with the value of the collection. For that, I used the replace function in a loop like this:

Replace("[Collection.Name]", "[Collection.Name]", [Collection.Name])

With this function it replace everything that I have stored in the dataitem with the [Collection.Name] and I want to replace just that part.

How can I do it?

------------------------------
Madalina Acsinte
------------------------------

The first argument to put into the Replace function is the name of the data item that contains all the HTML. If your HTML text is in a data item called [HTML text], then the Replace function should look like this:
Replace([HTML text], "[Collection.Name]", [Collection.Name])

------------------------------
Dave Morris
Cano Ai
Atlanta, GA
------------------------------

Dave Morris, 3Ci at Southern Company

Hi,

Actually while using Replace Function follow like this,
Replace(Data item in which your actual entire HTML text is present, which part of HTML text you want to change, With which value you want to replace it with)

For example: Replace([My HTML], "[Collection.Name]", [Collection.Name])

Note: For Data item there is no need of Double Quotes surrounded by Square Brackets. (i.e., Replace("[Collection.Name]", "[Collection.Name]", [Collection.Name]))

Hope this solved your query. If not please let me know.


------------------------------
Yeswa Vaibhav Alwar Nerella
Associate Consultant
Capgemini
Asia/Kolkata
------------------------------