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 Notification Request Number and all its RITM

Fredo1
Giga Expert

I want to send an email with a summary with the Request Number and all the RITM's

I have the following script

template.print('<p>' + 'Click here to view request: ' + '${request.URI_REF}');

template.print("<br />");

template.print("Summary of Requested items:");

template.print("<br />");

var gr = new GlideRecord("sc_req_item");

//gr.addQuery("request", current.sys_id);

gr.addQuery("sys_id", current.sysapproval);

gr.query();

while(gr.next()) {

      }

      template.print(gr.number + ":   " + gr.cat_item.getDisplayValue());

}

But, I only get this

Click here to view request: REQ0010312

Summary of Requested items:

undefined: undefined

Can you let me know what I have wrong?

Many thanks in advance...

1 ACCEPTED SOLUTION

Please check now, above code contains brackets closed between while and template. Now copy paste the exact code and check the results and please let me know.



template.print('<p>' + 'Click here to view request: ' + '${request.URI_REF}');


template.print("<br />");


template.print("Summary of Requested items:");


template.print("<br />");


var gr = new GlideRecord("sc_req_item");


gr.addQuery('request',current.request);


gr.query();


while(gr.next()) {


//}   remove this line, because of this it prints one record only.


      template.print(gr.number + ":   " + gr.cat_item.name);


}


View solution in original post

19 REPLIES 19

try with this script,



template.print('<p>' + 'Click here to view request: ' + '${request.URI_REF}');


template.print("<br />");


template.print("Summary of Requested items:");


template.print("<br />");


var gr = new GlideRecord("sc_req_item");


gr.addQuery('sys_id',current.sys_id); replace this line with previous


gr.query();


while(gr.next()) {


      }


      template.print(gr.number + ":   " + gr.cat_item.getDisplayValue());


}


Getting close



I just got one request item displayed out of 3 that I submitted



Any more ideas and thanks


Try this one and let me know,



template.print('<p>' + 'Click here to view request: ' + '${request.URI_REF}');


template.print("<br />");


template.print("Summary of Requested items:");


template.print("<br />");


var gr = new GlideRecord("sc_req_item");


gr.addQuery('request',current.request);


while(gr.next()) {


      }


      template.print(gr.number + ":   " + gr.cat_item.getDisplayValue());


}


It displayed only one requested item and this time the middle one...


sorry you want RITMs right, so you need to query from sc_request table. Try this one definitly you can achieve your answer.



template.print('<p>' + 'Click here to view request: ' + '${request.URI_REF}');


template.print("<br />");


template.print("Summary of Requested items:");


template.print("<br />");


var gr = new GlideRecord("sc_request");


gr.addQuery('sys_id',current.request);


while(gr.next()) {


      }


      template.print(gr.number + ":   " + gr.cat_item.getDisplayValue());


}