- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2015 10:31 AM
I have created a document in Managed Documents that is basically a form for a requester to fill out and return if a release is of a particular category (Enhancement).
How would I go about generating an email (notification) from a release's work flow with this document attached to the email? We would expect them to complete the form and email it to the Assigned to user (the instructions would be in the email).
I figure I could create an event in the workflow and then send a notification based on that event being triggered. The thing is, how would I go about coding the attaching of this document from the Managed Documents into the email?
Thanks for any assistance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2016 11:14 AM
I couldn't figure out a way to drop in a document to an email before sending it. I tried a lot of things but nothing worked properly. So, instead, I went about it a different way:
1. Created a business rule the would run when a release met certain criteria (in the when to run tab, when=after). In the advanced tab I entered the following code:
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
var myEvent = "rm_feature.oracle_enhancement";
attachEnhancmentform();
gs.eventQueue(myEvent, current, gs.getUserID(), gs.getUserName());
}
function attachEnhancmentform(){
var enhcDoc= new GlideRecord('dms_document');
enhcDoc.addQuery('name', 'Enhancement Request Form'); //this is the name of the document i added to managed documents
enhcDoc.addQuery('active', 'true');
enhcDoc.query();
//Get doc revision
while (enhcDoc.next() ){
var docSysid= enhcDoc.sys_id;
var docRev= new GlideRecord('dms_document_revision');
docRev.addQuery('Document', enhcDoc.number);
docRev.query();
while (docRev.next()){
var docRevsysid = docRev.sys_id;
GlideSysAttachment.copy('dms_document_revision', docRevsysid, 'rm_feature', current.sys_id); //this attaches the document to the release
}
}
}
2. You can see in the above code (5th line) that I create an event named "rm_feature.oracle_enhancement" (from myEvent variable in line 3)
3. That event triggers an email notification to be sent to the requester from table Release [rm_release]. The notification is sent to the requester and in the tab, "What it will contain" I have checked "Include attachments". This will include the attachment that was attached in Step 1's business rule. One thing to keep in mind is that all attachments for the release will be included, but I did find ways to only include certain attachments in the community. That said, most of this will occur when the release is new and has no attachments
So that's how I did it. Not exactly what I wanted to do, but sometimes you go with your second plan.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2015 02:57 PM
Hi Eric,
The best way to send out an attachment with an email is copy the attachment to the sys_email record that goes out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2016 11:09 AM
So, I created the following email script and call it from the Email Notification. It generates the email but doesn't attach the document from managed documents. I thought that the bolded line (near the bottom of the code would do the magic, but it doesn't. Any suggestions to get me closer?
//CODE BELOW
attachEnhancmentform();
function attachEnhancmentform() {
var enhcDoc= new GlideRecord('dms_document');
enhcDoc.addQuery('name', 'Enhancement Request Form');
enhcDoc.addQuery('active', 'true');
enhcDoc.query();
while (enhcDoc.next() ){
var docSysid= enhcDoc.sys_id;
var docRev= new GlideRecord('dms_document_revision');
docRev.addQuery('Document', enhcDoc.number);
docRev.query();
while (docRev.next()){
var docRevsysid = docRev.sys_id;
gs.log ("Doc Rev Name: " + docRev.name);
var docAttachment = new GlideRecord ('sys_attachment');
docAttachment.addQuery('table_sys_id', docRev.sys_id);
docAttachment.query();
var attSysid ='';
var attFilename ='';
while (docAttachment.next()){
attSysid = docAttachment.sys_id;
attFilename = docAttachment.file_name
}
template.print('Attachment: <a href="http://'+gs.getProperty("our-dev-env")+'.service-now.com/sys_attachment.do?sys_id=' + docRevsysid + '">' + attFilename + '</a>\n');
GlideSysAttachment.copy('dms_document', docRevsysid, 'rm_feature', rlseSysid );
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2016 11:14 AM
I couldn't figure out a way to drop in a document to an email before sending it. I tried a lot of things but nothing worked properly. So, instead, I went about it a different way:
1. Created a business rule the would run when a release met certain criteria (in the when to run tab, when=after). In the advanced tab I entered the following code:
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
var myEvent = "rm_feature.oracle_enhancement";
attachEnhancmentform();
gs.eventQueue(myEvent, current, gs.getUserID(), gs.getUserName());
}
function attachEnhancmentform(){
var enhcDoc= new GlideRecord('dms_document');
enhcDoc.addQuery('name', 'Enhancement Request Form'); //this is the name of the document i added to managed documents
enhcDoc.addQuery('active', 'true');
enhcDoc.query();
//Get doc revision
while (enhcDoc.next() ){
var docSysid= enhcDoc.sys_id;
var docRev= new GlideRecord('dms_document_revision');
docRev.addQuery('Document', enhcDoc.number);
docRev.query();
while (docRev.next()){
var docRevsysid = docRev.sys_id;
GlideSysAttachment.copy('dms_document_revision', docRevsysid, 'rm_feature', current.sys_id); //this attaches the document to the release
}
}
}
2. You can see in the above code (5th line) that I create an event named "rm_feature.oracle_enhancement" (from myEvent variable in line 3)
3. That event triggers an email notification to be sent to the requester from table Release [rm_release]. The notification is sent to the requester and in the tab, "What it will contain" I have checked "Include attachments". This will include the attachment that was attached in Step 1's business rule. One thing to keep in mind is that all attachments for the release will be included, but I did find ways to only include certain attachments in the community. That said, most of this will occur when the release is new and has no attachments
So that's how I did it. Not exactly what I wanted to do, but sometimes you go with your second plan.