Split data of one text text row in pdf

Hi,

in one transactional PDF I’ve a single line for each record containing all data for a further process step (complement records).

This line {Metadata_begin]value1;value2;value3;value4…{Metadata_end} should be split in its contents with the leading and trailing {Metadata_begin} stripped. Best would be to export the values in separate variables or an array.

thx for any idea!

Ralf.

Hi RalfG,

I bit messy but gets the job done. This returns an array and prints out value1,value2,value3.

var str = “{Metadata_begin}value1;value2;value3;value4{Metadata_end}”;
var str2 = str.replace(“{Metadata_begin}”,“”);
str2 = str2.replace(“{Metadata_end}”,“”);
var res = str2.split(“;”);

results.html(res);

Hope this helps.

Regards,

S

var myLine = "{Metadata_begin}value1;value2;value3;value4{Metadata_end}";
var myArray = myLine.match("({Metadata_begin})(.*)({Metadata_end})")[2].split(";");

Then you can access each element with myArray[0], myArray[1], etc.

I knew someone would come back with a one liner or two :slight_smile: Nicely done!

exactly what I needed, thx!

One additional question. How to use that in datamapper and generating speaking variables like

CustomerNr =
MetaData.match(“({MetaDataBegin})(.*)({MetaDataEnd})”)[2].split(“;”)[0];

for the designer later on?

Or is it better to pass the whole array to designer?

It’s basically your choice: if you want to keep it simple in the Designer, then you can extract each array element in its own field in the DataMapper, that way you simply drag and drop those fields on your template in the Designer.

The easiest way to do that would be to create a record property named Metadata in your data mapping config. Set its type to Object. Then use an Action Step to store the above array in the property.

Then you can use standard extraction steps to store each element of the array into its own field (e.g. sourceRecord.properties.Metadata[0], sourceRecord.properties.Metadata[1], etc.)

But of course, you can also store the entire array in a single field (e.g. named Metadata) and then in the Designer, use JSON.parse(record.Metadata) to have access to the entire array.

As I said, it’s your pick.

works like a charm! THX!

esp. the Action Step is useful to do the extraction, matching and splitting, making it very convenient for the extraction to define neat names.

Ralf.