Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to capture richline text and empty fields in notifications

User_267
Tera Contributor

the below code is just capturing question and answer ( if the field is not empty) , how to modify this code so that it has to capture question which are empty fields  along with which are not empty and rich text label also. 

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);

1 REPLY 1

Dnyaneshwaree
Mega Sage

Hello @User_267 ,

Update and try this one:

function runMailScript(current, template, email, email_action, 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++) {
        var question = vs.get(i);
        var label = question.getLabel();
        var displayValue = question.getDisplayValue();
        
        // Including both empty and non-empty fields along with rich text labels
        if (label) {
            template.print(label + "::" + (displayValue ? displayValue : "No Answer Provided"));
            template.print("\n");
        }
    }
}

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

 

Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!!

Dnyaneshwaree Satpute
Tera Guru