Custom notification display of variable in email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 08:48 PM
We are facing some challenges to populate all variables in email notification using
var set = new GlideappvariablePoolQuestionSet();
set.setRequest(item.sys_id);
set.load();
Is it possible to load some set of variable for that item specific based on business needs insteads of entire form varirables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 10:36 PM
Hi @kumar G ,
Do you want to show only few variables based on some conditions?
You can create an email script using below code, I've added a comment in code where you can specify the condition to show only specific variables. Replace it with your own conditions -
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('sys_id', 'your ritm sys id');
ritm.query();
if (ritm.next()) {
var variables = ritm.variables.getElements();
for (var i = 0; i < variables.length; i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var value = question.getDisplayValue();
if (label != '' && value != '') {
// Specify condition here which variables should be visible
if(value == 'xyz') {
template.print(label + " = " + value + "<br/>");
}
}
}
}
Call the email script in your notification - ${mail_script:email_script_name}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 12:03 AM
Hi @kumar G
Yes, you can load specific sets of variables for a given item (such as an incident, request, or task) based on your business needs. The GlideappvariablePoolQuestionSet API allows you to work with sets of variables associated with a particular item.
Here's an example of how you can load specific sets of variables for an item:
// Create a new GlideappvariablePoolQuestionSet object
var set = new GlideappvariablePoolQuestionSet();
// Set the item (record) ID for which you want to load variables
var itemId = 'your_item_sys_id_here'; // Replace 'your_item_sys_id_here' with the actual item Sys ID
set.setRequest(itemId);
// Load the variables for the specified item
set.load();
// Now you can work with the loaded variables
// For example, you can iterate over the variables and retrieve their values
while (set.hasNext()) {
var question = set.next();
var questionText = question.getQuestionText();
var answer = question.getDisplayValue();
// Do something with the question and answer
}
In this script:
- Replace 'your_item_sys_id_here' with the actual Sys ID of the item for which you want to load variables.
- The set.load() method loads the variables associated with the specified item.
- You can then iterate over the loaded variables using methods like set.hasNext() and set.next() to retrieve each variable's details, such as the question text and display value.
By using this approach, you can target specific sets of variables associated with an item and work with them according to your business needs, rather than loading all variables for the entire form.
Mark Accept as Solution & HIT helpful !!!