How to get catalog variable question and Selected value into email Notification (should support language)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2017 10:16 AM
Hi All,
I need to send email notification to requestor with Catalog variable and selected label based on user language
Example :
Scripted used in email script :
// a is name of the catalog variable
function Name(a) {
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
if (vs.get(i).getName() == a) {
return vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue();
}
}
}
This script returns question and selected label but it is returning only english i need a script which can support every language . service catalog support multiple language's.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2017 11:04 AM
Have you tried "gs.getMessage(vs.get(i).getLabel());" ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2017 11:30 AM
Hey Sankeerth,
Try to create a notification Script with the Below script and use the notification script in your email. Currently its working for all the Questions and values in the Request.
(function runMailScript(current, template, email, email_action, event) {
template.print("Summary of Catalog item:\n");
var scTask=new GlideRecord('sc_task');
scTask.addQuery("sys_id", current.sys_id);
scTask.query();
//gs.log(current.sys_id);
while(scTask.next())
{
var id = scTask.request_item;
//gs.log(id);
var scReqItem = new GlideRecord("sc_req_item");
scReqItem.addQuery("sys_id", id.toString());
scReqItem.query();
//gs.log(id.toString());
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.request_item);
varown.orderBy("sc_item_option.order");
varown.query();
//gs.log(current.request_item);
while (varown.next()) {
var visible = varown.sc_item_option.item_option_new.visible_summary;
//gs.log(visible);
//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);
//gs.log(question);
question.setValue(varown.sc_item_option.value);
if (question.getLabel() != "" && question.getDisplayValue() !="" && question.getDisplayValue()!='false'&& visible == true)
{
//template.space(4);
template.print(' ' + question.getLabel() + " = " + question.getDisplayValue() + "<br/>");
}
}
}
}
})(current, template, email, email_action, event);
Thanks
Raghu
----------------------------------------------------------------------------------------------------
Please like or mark it helpful / correct based on the impact of this reply.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2020 10:46 AM
I don't know if this would work, but if a variable's getLabel method retains language it might.
(function runMailScript(current, template, email, email_action, event) {
var ritm = new GlideRecord('sc_req_item');
ritm.get(/* YOUR RITM SYS_ID HERE */);
var variable_names = Object.keys(ritm.variables); // Get all the keys in the RITM's variables object
var string = '';
for (var index = 0; index < variable_names.length - 1; ++ index) {
var variable = ritm.variables[variable_names[index]];
string += variable.getLabel() + " " + variable.getDisplayValue() + "<br>"; // Get the label and display value of each variable
}
template.print(string);
})(current, template, email, email_action, event);