How to pull the sctask short description and populated in the request subject notification email

Carol2
Tera Contributor

Hi, 

 

I have a requirement to pull the sctask short description and populate that short description in the request email notification. How do I achieve that, please help.

 

The subject should be as show below 

 

Request REQ000001 - "short description from the sctask record" was approved

 

Regards 

Ca

1 ACCEPTED SOLUTION

Mark Manders
Mega Patron

You will need to set the subject through an email script, since you can't get it directly from the config screen.

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

	var reqNr = current.number.getDisplayValue();
	var subject = '';
	var shortDesc = '';
	var shortDescTask = new GlideRecord('sc_task');
	shortDescTask.addQuery('request', current.getUniqueValue());
	shortDescTask.query();
	if (shortDescTask.next()) {
		shortDesc = shortDescTask.short_description;
	} 
	subject = reqNr + " - " + shortDesc + " was approved";

	email.setSubject(subject);

})(current, template, email, email_action, event);

 

This is assuming there is only one task and the notification is triggered from the Request record. 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

2 REPLIES 2

anshul_goyal
Kilo Sage

Hello @Carol2,

To achieve the below requirement, create a notification on the request table. Then, use an email script where you perform a GlideRecord query on the sc_task table to check the current request record. Fetch the 'short description' from the sc_task table and include it in the subject.

 

// Initialize a GlideRecord for the 'sc_task' table
var taskRef = new GlideRecord('sc_task');

// Check if there is a record in 'sc_task' where the 'request' field matches the current record's unique value
if (taskRef.get('request', current.getUniqueValue())) {
    // Ensure the 'short_description' field is populated
    if (!gs.nil(taskRef.short_description)) {
        // Construct the email subject using the current record's number and the task's short description
        var taskDescription = taskRef.getValue('short_description'); // Use getValue() for consistent coding standards
        var currentNumber = current.getValue('number'); // Use getValue() for clarity
        email.setSubject('Request ' + currentNumber + ' ' + taskDescription + ' was approved');
    }
}

 


Please mark my solution as Helpful and Accepted, if it works for you in any way!

Thanks

Mark Manders
Mega Patron

You will need to set the subject through an email script, since you can't get it directly from the config screen.

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

	var reqNr = current.number.getDisplayValue();
	var subject = '';
	var shortDesc = '';
	var shortDescTask = new GlideRecord('sc_task');
	shortDescTask.addQuery('request', current.getUniqueValue());
	shortDescTask.query();
	if (shortDescTask.next()) {
		shortDesc = shortDescTask.short_description;
	} 
	subject = reqNr + " - " + shortDesc + " was approved";

	email.setSubject(subject);

})(current, template, email, email_action, event);

 

This is assuming there is only one task and the notification is triggered from the Request record. 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark