Request Completed - Email Notification - Show all RITMs and respective variables

Chase Stevenson
Mega Guru

Greetings -

I have been using the following email scripts to show catalog item variables in email notifications to customers, but I cannot get them to work for the "Request Completed" email notification that is sent to the customer upon REQ completion.

Script used for "RITM Approved" Email Notification:

<mail_script>
template.print("Summary of Requested Item:"+ "<br/>");
//var keys = new Array;
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.sys_id.toString());
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
if (vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue()!='' && vs.get(i).getDisplayValue()!='false') {
template.space(4);
template.print(' ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "<br/>");
}
}
</mail_script>

And script used for a custom "Approval Request RITM" email notification sent to RITM approvers:

<mail_script>   
template.print("Summary of Requested item:\n");     
var gr = new GlideRecord("sc_req_item");   
gr.addQuery("sys_id", current.sysapproval);   
gr.query();   
while(gr.next()) { 
template.print(gr.number + ":   " + gr.quantity + " X " + gr.cat_item.getDisplayValue() + "\n");   
template.print("       Options:\n");   
var varown = new GlideRecord('sc_item_option_mtom');   
varown.addQuery("request_item", current.sysapproval);
varown.orderBy("sc_item_option.order");     
varown.query();   
while (varown.next()){   
var visible = varown.sc_item_option.item_option_new.visible_summary;   
var question = GlideappAbstractChoiceListQuestion.getQuestion(varown.sc_item_option.item_option_new);     question.setValue(varown.sc_item_option.value);   
if (question.getLabel() != "" && question.getDisplayValue() != "" && visible == true && varown.sc_item_option.item_option_new.type.getDisplayValue().indexOf('Container')==-1){   
template.space(4);   
template.print('         ' +   question.getLabel() + " = " + question.getDisplayValue() + "\n");   
    }   
    }   
    }   
</mail_script>

Each script is working and showing the variables of the RITM.

I want to customize the "Request Completed" email notification to show the variables of the RITMs that were underneath the REQ in the same way as the scripts above do.

Can anybody help me edit the above scripts or provide a new script that will achieve this? Would look something like this:

find_real_file.png

1 ACCEPTED SOLUTION

Shashikant Yada
Tera Guru

Can you try the below mail script:

<mail_script>
template.print("Summary of Requested item:\n");
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sys_id); //Changed
gr.query();
while(gr.next()) {
template.print(gr.number + ": " + gr.quantity + " X " + gr.cat_item.getDisplayValue() + "\n");
template.print(" Options:\n");
var varown = new GlideRecord('sc_item_option_mtom');
varown.addQuery("request_item", gr.sys_id); //Changed
varown.orderBy("sc_item_option.order");
varown.query();
while (varown.next()){
var visible = varown.sc_item_option.item_option_new.visible_summary;
var question = GlideappAbstractChoiceListQuestion.getQuestion(varown.sc_item_option.item_option_new); question.setValue(varown.sc_item_option.value);
if (question.getLabel() != "" && question.getDisplayValue() != "" && visible == true && varown.sc_item_option.item_option_new.type.getDisplayValue().indexOf('Container')==-1){
template.space(4);
template.print(' ' + question.getLabel() + " = " + question.getDisplayValue() + "\n");
}
}
}
</mail_script>

Thanks
Shashikant

Hit Helpful or Correct on the impact of response.

View solution in original post

3 REPLIES 3

Shashikant Yada
Tera Guru

Can you try the below mail script:

<mail_script>
template.print("Summary of Requested item:\n");
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sys_id); //Changed
gr.query();
while(gr.next()) {
template.print(gr.number + ": " + gr.quantity + " X " + gr.cat_item.getDisplayValue() + "\n");
template.print(" Options:\n");
var varown = new GlideRecord('sc_item_option_mtom');
varown.addQuery("request_item", gr.sys_id); //Changed
varown.orderBy("sc_item_option.order");
varown.query();
while (varown.next()){
var visible = varown.sc_item_option.item_option_new.visible_summary;
var question = GlideappAbstractChoiceListQuestion.getQuestion(varown.sc_item_option.item_option_new); question.setValue(varown.sc_item_option.value);
if (question.getLabel() != "" && question.getDisplayValue() != "" && visible == true && varown.sc_item_option.item_option_new.type.getDisplayValue().indexOf('Container')==-1){
template.space(4);
template.print(' ' + question.getLabel() + " = " + question.getDisplayValue() + "\n");
}
}
}
</mail_script>

Thanks
Shashikant

Hit Helpful or Correct on the impact of response.

This worked and displays the following:

find_real_file.png

Can you propose a way to include a break between the RITMs after the last variable of each so that it's easier to look at?

Yes just modify below line template.print("\n"+ gr.number + ": " + gr.quantity + " X " + gr.cat_item.getDisplayValue() + "\n");