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- get RITM variables

Sironi
Kilo Sage

Hi,

some one help me how to show below details in email notification

find_real_file.png

 

how to show Owner name in Notification body

 

template.print("<b>Summary of Requested items:\n</b>");
var item = new GlideRecord("sc_req_item");
if (item.get(current.document_id)) {
template.print("<b>"+item.number + ": " + item.cat_item.getDisplayValue() + "</b><br/>");
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(item.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
if (vs.get(i).getDisplayValue() != '') {
template.print("<b>"+vs.get(i).getLabel() +"</b>"+ " : " + vs.get(i).getDisplayValue() + "<br/>");
}
}
}

find_real_file.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Sironi 

As mentioned by Pradeep you need to query the table and get the value

Sample script below which is updated

Ensure you give valid table names, list variable name , field names, etc

template.print("<b>Summary of Requested items:\n</b>");
var item = new GlideRecord("sc_req_item");
if (item.get(current.document_id)) {
template.print("<b>"+item.number + ": " + item.cat_item.getDisplayValue() + "</b><br/>");
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(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).getName() != 'listVariableName') {
template.print("<b>"+vs.get(i).getLabel() +"</b>"+ " : " + vs.get(i).getDisplayValue() + "<br/>");
}

if(vs.get(i).getName() == 'listVariableName'){

var gr = new GlideRecord('table name'); // give table name being referred by list variable

gr.addQuery('sys_id', 'IN', item.variables.<listVariable>);

gr.query();

while(gr.next()){

template.print('Owner is' + gr.<ownerField> + '<br/>');

}

}
}
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

13 REPLIES 13

@Sironi 

Hope you are doing good.

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi 

Can you please help me on the script. My requirement is based on the approver selected variables should get populated along with few common variables.

Example: I am having below checkboxes and few common variables like Requested For, Location, Manager, Department, Requested By and checkboxes like Finance, QA Finance, Sandbox, Corporate Planning and the approvals are different for those checkboxes. While submitting the request if I select Finance, Sandbox, Corporate Planning Finance Approver notification should see only Finance Variable checked. Below is the mail Script I have written but it is not working

template.print("Summary of Requested items:\n");
var item = new GlideRecord("sc_req_item");
item.addQuery("sys_id", current.sysapproval);
item.query();
while (item.next()) {
    var nicePrice = item.price.toString();
    if (nicePrice != '') {
        nicePrice = parseFloat(nicePrice);
        nicePrice = nicePrice.toFixed(2);
    }
    template.print("    Options:\n");

    var keys = new Array();
    var set = new GlideappVariablePoolQuestionSet();
    set.setRequestID(item.sys_id);
    set.load();
    var vs = set.getFlatQuestions();
    gs.info("Current Approver" + current.approver);
   

        for (var i = 0; i < vs.size(); i++) {
            if (vs.get(i).getDisplayValue() != "false" && vs.get(i).getDisplayValue() != "" && (vs.get(i).getLabel() == 'PASA Finance Sandbox' || vs.get(i).getLabel() == 'Finance' || vs.get(i).getLabel() == 'QA Finance')) {
                template.space(4);
               
                template.print('     ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");
               
            }
           
       }
   

   
}

Devi
Tera Contributor

Updating the mail script

 

template.print("Summary of Requested items:\n");
var item = new GlideRecord("sc_req_item");
item.addQuery("sys_id", current.sysapproval);
item.query();
while (item.next()) {
    var nicePrice = item.price.toString();
    if (nicePrice != '') {
        nicePrice = parseFloat(nicePrice);
        nicePrice = nicePrice.toFixed(2);
    }
    template.print("    Options:\n");

    var keys = new Array();
    var set = new GlideappVariablePoolQuestionSet();
    set.setRequestID(item.sys_id);
    set.load();
    var vs = set.getFlatQuestions();
    gs.info("Current Approver" + current.approver);
    if (current.approver == 'bf8ae18af549490072b64ef71b35e6df') {
   

        for (var i = 0; i < vs.size(); i++) {
            if (vs.get(i).getDisplayValue() != "false" && vs.get(i).getDisplayValue() != "" && (vs.get(i).getLabel() == 'PASA Finance Sandbox' || vs.get(i).getLabel() == 'PASA Finance' || vs.get(i).getLabel() == 'PASAQA Finance')) {
                template.space(4);
               
                template.print('     ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");
               
            }
           
       }
    }

   
}

Devi
Tera Contributor

I am getting as below I am not getting the common variables.

 

Devi_1-1711550081822.png