- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2025 03:44 AM
Hi Team
please check if this scheduled job script is ok or if i am missing something?
var gr = new GlideRecord('sc_req_item');
gr.addQuery('state', 'Closed Complete');
gr.addQuery('cat_item', '89a103df8710da1016a443770cbb3523'); // Replace with your catalog item sys_id
gr.query();
while (gr.next()) {
// Check if select_variable is 'developer' or 'designer'
if (gr.variables.request_template == 'Developer' || gr.variables.request_template == 'Designer') {
// Schedule a notification job to run 1 hour later
var job = new GlideRecord('sys_trigger');
job.initialize();
job.name = 'Send Closed Request Notification';
job.script = "sendClosedRequestNotification('" + gr.sys_id + "');";
job.next_action = new GlideDateTime();
job.next_action.addSeconds(3600); // 1 hour later
job.insert();
}
}
// Define the function to send the email
function sendClosedRequestNotification(requestItemSysId) {
var gr = new GlideRecord('sc_req_item');
if (gr.get(requestItemSysId)) {
// Prepare email details
var emailBody = "Your request has been closed.\n\n";
emailBody += "Request Number: " + gr.number + "\n";
emailBody += "Requested Item: " + gr.cat_item.getDisplayValue() + "\n";
emailBody += "Requested For: " + gr.requested_for.getDisplayValue() + "\n";
emailBody += "Description: " + gr.description + "\n";
// Add requested item variables
emailBody += "Requested Item Details:\n";
emailBody += "Variable 1: " + gr.variables.request_template + "\n"; // Replace 'variable1' with the actual variable name
emailBody += "Variable 2: " + gr.variables.description + "\n"; // Replace 'variable2' with the actual variable name
// Add more variables as needed
// Send Email
var email = new GlideEmailOutbound();
email.setSubject("Your Request is Closed");
email.setBody(emailBody);
email.setTo(gr.requested_for.email + ", second.recipient@example.com"); // Replace with the appropriate email addresses
email.send();
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2025 06:52 PM
Thank You Ankur
Legend!
btw
i am from the same city as u, but currently overseas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2025 04:00 AM
update this line as 3 means close complete. use that and share us the results
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2025 06:52 PM
Thank You Ankur
Legend!
btw
i am from the same city as u, but currently overseas