I haven't tested this, but I added an orderBy query on line 12 that I think will get the job done.



<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 = Packages.com.glideapp.questionset.Question.getQuestion(varown.sc_item_option.item_option_new);
question.setValue(varown.sc_item_option.value);
if (question.getLabel() != "" &amp;&amp; question.getDisplayValue() != "" &amp;&amp; visible == true){
template.space(4);
template.print(' ' + question.getLabel() + " = " + question.getDisplayValue() + "\n");
}
}

}
</mail_script>


I couldn't find any documentation on it anywhere, but have discovered if you set the 'Visible on Summaries' field on the variable form to false, it will stop it from adding that variable on the email using Brad's script.
This came in real handy when I had a workflow variable that I really didn't need the approver to see.


Hi, i have a similar requirement. I tried this script.

But at the line "Packages.com.glideapp.questionset.Question.getQuestion(varown.sc_item_option.item_option_new);" it doesnt do anything

I mean it doesn't log or throw any error.

Any idea why is it happening? Do i need to activate any plugin for this package?


if you are on Calgary then you need to replace the Packages call
//before Calgary
//var question = Packages.com.glideapp.questionset.Question.getQuestion(varown.sc_item_option.item_option_new);
on Calgary
var question = GlideappAbstractChoiceListQuestion.getQuestion(varown.sc_item_option.item_option_new);

entire script would be something like this

template.print("Summary of Requested item:\n");
var scReqItem = new GlideRecord("sc_req_item");
scReqItem.addQuery("sys_id", current.sysapproval.toString());
scReqItem.query();

while (scReqItem.next()) {
gs.print(scReqItem.number + ": " + scReqItem.quantity + " X " + scReqItem.cat_item.getDisplayValue() + "\n");
gs.print(" Options:\n");

var varown = new GlideRecord('sc_item_option_mtom');
varown.addQuery("request_item", current.sysapproval.toString());
varown.orderBy("sc_item_option.order");
varown.query();

while (varown.next()) {
var visible = varown.sc_item_option.item_option_new.visible_summary;
//var question = Packages.com.glideapp.questionset.Question.getQuestion(varown.sc_item_option.item_option_new);//Packages call replaced with line below on CAlgary+
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) {
template.space(4);
template.print(' ' + question.getLabel() + " = " + question.getDisplayValue() + "\n");
}
}
}


for more information on Packages calls replacement make sure you take a look at http://wiki.servicenow.com/index.php?title=Packages_Call_Replacement_Script_Objects


Gotcha ! Awesome.. Thanks