Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Adding line breaks between variables in email script

sarahjantz
Tera Expert

I'm using the mail script below to pull variables from a requested item into a notification, but I'd like to insert a line break between each variable. How would I accomplish this? I assume it is in the line that is red below because it is inserting :: between each variable instead of a line, but I'm not sure how to tell it to insert a line break instead. 

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {



    var set = new GlideappVariablePoolQuestionSet();
    set.setRequestID(current.request_item.sys_id); //changed
    set.load();
    var vs = set.getFlatQuestions();
    for (var i = 0; i < vs.size(); i++) {
        if (vs.get(i).getDisplayValue() != '' && +vs.get(i).getLabel() != '') {
            template.space("\n");
            template.print("\n" + vs.get(i).getLabel() + "::" + vs.get(i).getDisplayValue() + "\n");
        }
    }
})(current, template, email, email_action, event);

 

 

1 ACCEPTED SOLUTION

Sainath N
Mega Sage

@sarahjantz : I modified your code; please try it below. Please make sure that the "Newlines to HTML" checkbox is checked on the email script.

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    var set = new GlideappVariablePoolQuestionSet();
    set.setRequestID(current.request_item.sys_id);
    set.load();
    var vs = set.getFlatQuestions();
    for (var i = 0; i < vs.size(); i++) {
        if (vs.get(i).getDisplayValue() != '' && +vs.get(i).getLabel() != '') {
            template.print(vs.get(i).getLabel() + "::" + vs.get(i).getDisplayValue());
            template.print("\n");
        }
    }

})(current, template, email, email_action, event);

  

sainathnekkanti_0-1703202477782.png

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

 

View solution in original post

2 REPLIES 2

Sainath N
Mega Sage

@sarahjantz : I modified your code; please try it below. Please make sure that the "Newlines to HTML" checkbox is checked on the email script.

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    var set = new GlideappVariablePoolQuestionSet();
    set.setRequestID(current.request_item.sys_id);
    set.load();
    var vs = set.getFlatQuestions();
    for (var i = 0; i < vs.size(); i++) {
        if (vs.get(i).getDisplayValue() != '' && +vs.get(i).getLabel() != '') {
            template.print(vs.get(i).getLabel() + "::" + vs.get(i).getDisplayValue());
            template.print("\n");
        }
    }

})(current, template, email, email_action, event);

  

sainathnekkanti_0-1703202477782.png

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

 

Thank you!!