2021.1

Table Of Contents
label.find('@ProductLabel@').text(record.tables.products
[i].ProductDescription);
labelStr += label;
}
results.after(labelStr);
Use replace()
When personalizing HTML fragments retrieved from a snippet or from the template itself,
JavaScript's replace() method shows the best performance.
Replace() can only be used on Strings, while the commands loadhtml() and query() return or
a QueryResult, which is a set of strings, like the results object.
A QueryResult allows you to perform DOM manipulations like adding and removing elements,
adding and removing CSS classes etc. When the required manipulations are limited to
find/replace actions, you could change the QueryResult into a string. This allows you to replace
text using the replace() method.
For this, you could use toString():
var labelSnippet = loadhtml('snippets/label.html').toString();
Or you could copy the HTML of the QueryResults to a variable:
var block = results.html();
Example
var labelSnippet = loadhtml('snippets/label.html').toString();
var labelStr = "";
for( var i = 0; i < record.tables.detail.length; i++) {
var label = labelSnippet;
label = label.replace('#', i);
label = label.replace('@product@', record.tables.detail[i].fields
['product']);
label = label.replace('@notes@', record.tables.detail[i].fields
['notes']);
label = label.replace('@netweight@', record.tables.detail
[i].fields['netweight']);
labelStr += label;
}
results.after(labelStr);
Page 885