0 votes


someone knows how to make a line break in a script for the running of a runscript for an email template.

I want to replace the splash in this function with a line break

var nature = " ";
    var entyDS = Efficy.GetMasterDataSet(ContextHandle, 0);
    if(!entyDS || entyDS.IsEmpty) return "$$ENCODE$$" + nature;
    while(!entyDS.EOF) {
            nature = entyDS.fieldByName("R_F_NATURE_NIVEAU_1").asString+' / '+entyDS.fieldByName("R_F_NATURE_NIVEAU_2").asString+' / '+entyDS.fieldByName("R_F_NATURE_NIVEAU_3").asString;
    return nature;

I thank you in advance,

Sincerely, Jean.

asked in WorkFlow / Serverscript by (102 points)

2 Answers

+1 vote

Starting from Efficy 11.0, you can use modules for templates and have some variables available about the template context, like the language and the template format.


// Real module
return {
    debug: true,
    key: strToFloatDef(variables.values('TMPL_KEY'), 0),
    format: variables.values('TMPL_FORMAT'),        // e.g. DOCX (document)
    language: variables.values('TMPL_LANGUAGE'),    // e.g. NL
    encodeText: function(text) {
        switch (this.format.toUpperCase().split(" ")[0]) {
            case "HTML": 
            case "DOCX":
            case "XLSX":
            case "PPTX": return EscapeHtml(text); break;
            case "RTF": return EscapeRTF(text); break;
        return text;
    getLineSeparator: function() {
        return "[$LF]";
    getSpaceSeparator: function() {
        return " ";

This module is used in the template script below, stored in the custombase (not any longer in SYS_STORAGE). Note the module argument on the RunScript tag.

@import "ecma";
@import templateContext from "custom/template/context";

 * [$RunScript('multipleLines', module='custom/template/mergeScript')]
function multipleLines(editId) {
    var options = {
        editId: editId

    var lines = ["Lorem ipsum dolor sit amet <Kristof>, consectetur adipiscing elit",
        "Fusce at nisl eu dui vestibulum elementum",
        "Ut felis ex, imperdiet quis magna quis"]

    return templateContext.encodeText(lines.join(templateContext.getLineSeparator()));

This results into the following result in a Docx when opened in Word. This means that the [$LF] tag can be used also in office xml document formats, even if it's encoded again. Note the tag in the comment. If this was not escaped, the file would be corrupt.

enter image description here

answered by (6.8k points)
0 votes

Dear Jean,

So for line breaking in TemplateScript you can use :

For RTF or DOC templates:

var carriageReturnChar = '[$LF]';

For HTML templates:

var carriageReturnChar = '<br />';

For DOCX templates:

var carriageReturnChar = '<w:br/>';

Hope this will help.


answered by (1.8k points)
1,167 questions
1,425 answers
325 users