- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2022 09:37 AM
I have a request to add two items to the email notification that is configured via the sysapproval_approver table. The ask is to add the category and subcategory from the Change itself into the body of the email. Now the fields available do not seem to be helping me add those, I have tried multiple formats like current.change_request.(fieldname) and it's not working. I have looked at using the email template of change.itil.approver.role in the what it contains area but that's overkill by a lot, they don't want all of the details.
I have tried changing the table in the notification field to change_request but then the triggers don't work and can't be set up properly to key on the approvers field. Does this have to be a mail script and if so, how difficult is that to set up?
Solved! Go to Solution.
- Labels:
-
Change Management
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2022 11:13 AM
This:
${mailto.script:change_email_info}
Should be:
${mail_script:change_email_info}
The mailto is something different, I should have cropped that out of my screenshot to avoid confusion. It is to create email links (like an HTML mailto link to open a new email message).
For your email script, I would use this:
var html = "";
var gr = new GlideRecord(current.source_table);
if (gr.get(current.document_id)) {
html = "<strong>Category: </strong>" + gr.u_request_type + "\n";
html += "<strong>Subcategory: </strong>" + gr.u_subcategory;
}
template.print(html);
- The "\n" is a line break.
- The gr.get should have an "if" just in case it fails. That should never happen but I always put it in just in case something very unexpected happens.
- I am assuming the gr.u_request_type is your category field.
I haven't debugged the email script but that should work. Any questions just let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2022 09:56 AM
Use sysapproval as the prefix. Here is an example of one of our change approvals:
Remember, you are dotwalking from the "Approval for" value within the Variable Editor (that's why you use sysapproval):
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2022 10:09 AM
Normally, you would just using the Approval for field and dotwalk to your fields. This will have access to all of your Task-table fields. I had written up a reply on this (and deleted it), but then double checked and the Category field you are looking for is not there because it's not on the base Task table.
The current object is referencing the sysapproval_approver record, so you need to dotwalk to the Approval for column. That's why current.change_request does not work, change_request is not a valid column.
A mail script is an easy way to achieve this. Here is what it looks like in the notification. We simply place it at the spot we want it to be (around all our other formatting):
Here is the content of the mail script:
The key piece is having the template.print. This is what our output is. You'll noticed we put a slight bit of HTML formatting in place as well, just to make things look nice.
In your case, your mail script would do the same GlideRecord lookup, but instead your html variable would have gr.category and such in it. For example, it might be:
html = "<strong>Category: </strong>" + gr.category;
Any questions please let me know!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2022 10:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2022 10:58 AM
I for sure appreciate the help and you've pointed me in the right direction. I will show you what I have and what is happening and if you could tell me if I am close or just way off at this point
The content of my email notification is as follows. When I preview that, the body completely blank. If I take the mailto line out, it does populate
Dear ${approver},
You have an emergency approval for ${sysapproval.number} (${sysapproval.short_description}) that requires action.
${mailto.script:change_email_info}
Please log into ServiceNow to view the request and take action on this approval at your earliest convenience. Replying to this email will not update the approval.
You can also click here to go to the record that requires approval ${URI_REF}
Now my email script (which is probably the issue) is as follows