Document Template Script

Shalaka
Tera Contributor
    var tableBody;
    var tableBodyContent = '';
    var tableOpenTag = '<table cellpadding="5" class="detail-section-table">';
    var resultTable = "";
    var tableCloseTag = '</table>';
    var description = "<p>" + 'TestData ' + "</p>";
    var usrid;
    var usrname;
    var usrrole;
    var curDateTime = new GlideDateTime();
    var count = 0;
    var list = [];
    var subid;
    //var revID = current.u_number;
    //var revSysID = current.sys_id;
    var gr_accessrev = new GlideRecord('table_name');
    gr_accessrev.addQuery('u_review_id', revSysID );
    gr_accessrev.query();
    while (gr_accessrev.next()) {
        for (var i = 0; i <= count; i++) {
            subid = gr_accessrev.u_number;
            usrid = gr_accessrev.u_subscriber.user_name;
            usrname = gr_accessrev.u_subscriber.first_name + gr_accessrev.u_subscriber.last_name;
            tableBodyContent = 'TestData +
                '<tr>'+
   '<th>' +'SubID' +'</th>'+
    '<th>' + 'UserID'+'</th>'+
    '<th>' + 'UserName'+'</th>'+
 '</tr>'+
  '<tr>'+
    '<td>' +subid+'</td>'+
    '<td>' +usrid+'</td>'+
     '<td>' +usrname+'</td>'+
  '</tr>';
             tableBody = '<tbody>' + tableBodyContent + '</tbody>';
            resultTable = tableOpenTag + tableBody + tableCloseTag + '<br/>';
            template.print(resultTable) ;
        }
   
count++;
    }
   
This is the Template script to create HTML table and feed the data into it. But when I call it in Document Template(${template_script:name of template script}) it gives me the output as "Null".
 
But when I run it in Background script for testing it works. The output is the HTML Content , can someone suggest what is the issue?
OUTPUT:
*** Script: <table cellpadding="5" class="detail-section-table"><tbody>TestData <tr><th>SubID</th><th>UserID</th><th>UserName</th></tr><tr><td>0297</td><td>XYZ</td><td>XYZ</td></tr></tbody></table><br/>
*** Script: <table cellpadding="5" class="detail-section-table"><tbody>TestData <tr><th>SubID</th><th>UserID</th><th>UserName</th></tr><tr><td>0296</td><td>ABC</td><td>ABC</td></tr></tbody></table><br/>

1 REPLY 1

bammar
Kilo Sage
Kilo Sage

Perhaps when you call it call it like this

${template_script:name of template script}

 

leave out the Document Template () part

https://docs.servicenow.com/bundle/quebec-employee-service-management/page/product/human-resources/concept/document-template-scripts.html

See part 2 at the bottom.