- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2024 06:19 AM
Notification written in req table and customer need to RITM number in subject line
If single Req has multiple RITM means i need to show all RITM numbers in subject
Any one help on this, I think I will go for email script but I need any sample script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2024 06:33 AM
The script is pretty straightforward. Assuming that the request GR is contained in the "current" variable:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var requestedItems = [];
// Create a new GlideRecord for the 'sc_req_item' table
var requestedItemGR = new GlideRecord('sc_req_item');
// Query for requested items related to the current request
requestedItemGR.addQuery('request', current.getValue('sys_id'));
requestedItemGR.query();
while (requestedItemGR.next()) {
requestedItems.push(requestedItemGR.number.toString());
}
var subject = 'Requested Items Numbers: ' + requestedItems.join(', ');
// Set the subject for the email
email.setSubject(subject);
})(current, template, email, email_action, event);
Create a Notification Email Script and add it in the body of the notification. The "email.SetSubject()" is the part which will set the email subject. You can format the string argument as you desire.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2024 06:32 AM
Please refer the sample script -
// get the current record (REQ)
var currentRecord = new GlideRecord('req');
currentRecord.get(current.current);
// get a list of related RITMs
var grRelatedRITMs = new GlideAggregate('sc_req_item');
grRelatedRITMs.addQuery('parent', currentRecord.sys_id);
grRelatedRITMs.addAggregate('COUNT');
grRelatedRITMs.query();
// Initialize variables for subject and message body
var subject = '';
var body = '';
// creating subject line and message body based on the number of RITMs
if (grRelatedRITMs.next()) {
var numRITMs = grRelatedRITMs.getAggregate('COUNT');
if (numRITMs === 1) {
// Single RITM
var grRITM = new GlideRecord('sc_req_item');
grRITM.get(grRelatedRITMs.getValue('sys_id'));
subject = 'Notification for RITM: ' + grRITM.number;
body = 'This notification is related to RITM: ' + grRITM.number + '\n\n';
} else {
// Multiple RITMs
subject = 'Notification for REQ with multiple RITMs:';
body += 'This notification is related to the following RITMs:\n';
// get each RITM's number and append it to the subject and body
grRelatedRITMs.query();
while (grRelatedRITMs.next()) {
var grRITM = new GlideRecord('sc_req_item');
grRITM.get(grRelatedRITMs.getValue('sys_id'));
subject += ' ' + grRITM.number;
body += '- RITM: ' + grRITM.number + '\n';
}
}
// add additional notification details to the body
body += '\n' + currentRecord.comments + '\n'; // Assuming comments contain the notification details
// Send the email using GlideEmail or sysevent_email_action
if (subject !== '' && body !== '') {
var email = new GlideEmailOutbound();
email.setSubject(subject);
email.setBody(body);
email.addRecipient(current.variables.assigned_to); // Assuming assigned_to variable holds the recipient's email
email.send();
}
}
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2024 06:33 AM
The script is pretty straightforward. Assuming that the request GR is contained in the "current" variable:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var requestedItems = [];
// Create a new GlideRecord for the 'sc_req_item' table
var requestedItemGR = new GlideRecord('sc_req_item');
// Query for requested items related to the current request
requestedItemGR.addQuery('request', current.getValue('sys_id'));
requestedItemGR.query();
while (requestedItemGR.next()) {
requestedItems.push(requestedItemGR.number.toString());
}
var subject = 'Requested Items Numbers: ' + requestedItems.join(', ');
// Set the subject for the email
email.setSubject(subject);
})(current, template, email, email_action, event);
Create a Notification Email Script and add it in the body of the notification. The "email.SetSubject()" is the part which will set the email subject. You can format the string argument as you desire.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2024 09:04 PM
current.getValue('sys_id');
What it means current record where it will pick
Not working this code I kept log and checked it's not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2024 01:34 AM - edited ‎01-19-2024 01:35 AM
In this particular case, you add this email script to a notification. The table on which you have set the notification will determine the table and the condition when it triggers will determine the record. This is what determines the "current"