How to replace the specific record found in each of the record.fields with <br />?

The input file is an xml file containing a <fo:block> for formatting the paragraph. Where <fo:block> is present, the next text must start from the yan line. When the data is read from the xml file, it is desired that the intended formatting is implemented. The idea is to change <fo:block> to <br /> with the help of a script, but the problem is that there are many fields - more than 30. And that <fo:block> is not always in all fields.

Question - can I make a script that goes through all record.fields[xxxxx] and if <fo:block> is found in one of record.fields[xxxxx] then it changes it to <br />. Writing your own replace script for each field is time consuming and not very useful/correct. So I am looking for a more universal solution.

(Note from moderator: this post was reformatted so that the XML elements would be visible, for better readability).

It’s a bit difficult to figure out exactly what you mean without some sample data, but I would think that simply using a replace() in the Post function for your extracted fields would be enough to achieve what you want:

Thank you for your reply and suggestion. You have perceived and understood my data correctly. I will probably use this processing option as well. I had the following thought and the purpose of asking the question here is the following - is there a possibility to go through all record.fields with a for loop in a script and perform this replace operation. Because the client submits data to us and shows these paragraphs in different fields, in total there are about 30 fields where paragraphs can appear. So that’s the question I asked here, is there a way to not have to write a Post function for each one, but do it all in one place by writing a summary script. But I guess I will have to write the Post function for each one.

No need for a post processing script, You can add an Action step at the very end of the DM configuration with the following code:

let newRec = {}
for(f in record.fields){
  newRec[f] = record.fields[f].replace(/<fo:block>/gi,"<br />");

The solution is exactly what I was looking for, but we are using the 2018.1 version of Planetpress Connect Designer. Error running script (TypeError: Cannot find function set and object Record (#1). (#21)) (DME000019). Is there a solution for this?

No. The record.set() method was introduced in a later version. However, my first solution with the Post function would work in your version.

That said, you should really upgrade. You version is over 6 years old!

Your solution is very elegant and unfortunately we are still working with the old version and I will apply your first solution in this version. Thank you very much for your response, it saves a lot of time when looking for a solution. Thank you very much again and have a nice day!

Note that you could as well do a search / replace directly from Workflow using our name like plugin.

Thanks for the tip, because I just tried to manually apply replaceAll with notepad++ and it is a quick solution, and the same effect can be achieved with the Workflow plugin.
Thanks :slight_smile: