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.

Email Script Incident Activity

tomaslindev
Mega Guru

Good morning,
I need the activity of the incidents (attached images, comments, etc.) to be reflected in the email templates.
I have created an email script to call it later in the email template and be able to add everything, but it doesn't work for me. I am attaching the script.

 

(function runScript(current) {
    var sysId = current.sys_id;  
    var attachments = [];
    var comments = [];

    var grAttachments = new GlideRecord('sys_attachment');
    grAttachments.addQuery('table_sys_id', sysId);
    grAttachments.query();

    while (grAttachments.next()) {
        attachments.push({
            name: grAttachments.file_name.toString(),
            size: grAttachments.size_bytes.toString(),
            url: GlideServletURL.getApplicationURL() + '/sys_attachment.do?sys_id=' + grAttachments.sys_id.toString()
        });
    }

    var grComments = new GlideRecord('sys_journal_field');
    grComments.addQuery('element_id', sysId);
    grComments.query();

    while (grComments.next()) {
        comments.push({
            user: grComments.sys_created_by.toString(),
            comment: grComments.value.toString(),
            created: grComments.sys_created_on.toString()
        });
    }
    return {
        attachments: attachments,
        comments: comments
    };

})(current);


Any ideas? Thank you very much in advance and best regards.

0 REPLIES 0