- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2014 09:16 AM
Been looking at this little project for this afternoon
If a user is internal or a process user, they simply get a link to the attachment
If the user is a contact we ebond via email with we are looking to send them the attachment in the notification
I have seen the following thread and adapted a little more for our use (some extra checks and moving to GlideSysAttachment.copy)
Getting attachment in Email rather than link
All looking good and my code, gets to the end and the logs / debugging I have added get past the above copy command and onto the next statement.
What I am finding is that when I look at the email table, the notification I should have copied an attachment to has no attachments in the Attachments section
I have loaded a background script and run the GlideSysAttachment.copy command manually using the correct parameters, but I am not able to determine if it has actually copied or failed.
Is there a way to check that GlideSysAttachment.copy has worked
Should I see the attached attachment at the bottom of the sys_email record under the "attachments" section ?
Cheers
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2014 07:12 AM
so, following on from this sending attachments via WSDL - no duplicates
I am still using the attachment ebonding table to determine if the attachment has been sent to the 3rd party or not.
This way I can have a number of 3rd parties attached to the record and know that each has received the attachment. The issue with the other suggestions that I have seen and used as a basis are all adding a field to the sys_attachment table.
It is based on two components.
A Business Rule on the sys_attachment table
A Script Include which is called and is used to determine if this email needs to send attachments.
The Business Rule
// Initial variables
var strAdded = '';
var myRec = current.instance;
// get the members of the Recipients and create an array
var RecArr = current.recipients.split(',');
// Search the attachment table for the attachments for this record
var SAgr = new GlideRecord('sys_attachment');
SAgr.addQuery('table_sys_id',myRec);
SAgr.query();
// loop until we have checked all attachments
while (SAgr.next()) {
// for each attachment, we need to check each recipient
for (i=0;i<RecArr.length;i++)
{
// check to see if we "fullAttachmentSend" via EmailAddress
// or via the Noticification in use - we check to see if is a 3rd party Notification
if (new GroupMLongConditionList().sendAttachment(RecArr[i]) == true )
{
// check out table for this attachment and this user
uaegr = new GlideRecord('u_attachment_ebonding');
uaegr.addQuery('u_3rd_party',RecArr[i]);
uaegr.addQuery('u_attachment_sys_id',SAgr.sys_id);
uaegr.query();
//gs.log('add attachments uaegr has been queried');
// if we do not find a match, we have not sent an email
// update the table so we do not send this attachment again
if (!(uaegr.next()))
{
//gs.log('add attachments, nothing found in uaegr');
uaegr.initialize();
uaegr.u_3rd_party = RecArr[i];
uaegr.u_attachment_sys_id = SAgr.sys_id;
uaegr.insert();
// Add this attachment to a list of attachments already added
// If this attachment has not been added to this email, then add it, otherwise, why add again ?
// need this as this loops based on each recipient and if there is more than one to receive.
if (strAdded.indexOf(SAgr.sys_id) == -1)
{
var table = SAgr.table_name;
// where gr.sys_id is the sys_id on the attachment table and table = u_client_impact_record
// the line below copies all the attachments from the parent record, not the selected attachments.
//GlideSysAttachment.copy(SAgr.table_name,SAgr.sys_id,'sys_email',current.sys_id);
var SAIgr = new GlideRecord('sys_attachment');
SAIgr.initialize();
SAIgr.table_name = 'sys_email';
SAIgr.table_sys_id = current.sys_id;
SAIgr.file_name = SAgr.file_name;
SAIgr.compressed = SAgr.compressed;
SAIgr.content_type = SAgr.content_type;
SAIgr.size_byes = SAgr.size_bytes;
//SAIgr.size_compressed = SAgr.size_compressed;
SAIgr.insert();
// now we need to get over to the sys_attachment_doc table and copy each record
// that is associated with the old attachment to the new one
var SADgr = new GlideRecord('sys_attachment_doc');
var SADIgr = new GlideRecord('sys_attachment_doc');
SADIgr.initialize();
SADgr.addQuery('sys_attachment.sys_id',SAgr.sys_id);
SADgr.query();
while (SADgr.next())
{
SADIgr.data = SADgr.data;
SADIgr.length = SADgr.length;
SADIgr.position = SADgr.position;
SADIgr.sys_attachment = SAIgr.sys_id;
SADIgr.insert();
}
strAdded += SAgr.sys_id;
}
}
else
{
//gs.log('add attachments : matched a record so no send');
}
}
}
}
The script include call at line 27 was originally going to look to see if the notification was using a specific template, but I was not able to establish this, so now it is just simply passing an email address across and doing an if statement to determine if the attachment needs to be sent or not
sendAttachment : function (emailaddress) {
if(emailaddress.indexOf('@poyntz') != -1 || emailaddress.indexOf('poyntzj@outlook.com') != -1)
return true;
else
return false;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2014 09:21 AM
OK, found another document on GlideSysAttachment and I now have it working
in adapting it, the old command was looking like it was copying a specific attachment, whereas GlideSysAttachment.copy copies all the attachments from one record to another.
Bit of a pain as I want to copy an attachment at a time.
I shall investigate further
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2014 08:53 AM
I have now progressed and I can now copy a single attachment
in essence it is copying the entry in the sys_attachment table and then it has to copy all the associated records in the sys_attachment_doc table.
It would be nice if the contents of the sys_attachment_doc could be linked to more than one entry in the sys_attachment table
I am looking at one more thing which is used to determine if the attachments should be added, then the code will be uploaded
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2014 07:12 AM
so, following on from this sending attachments via WSDL - no duplicates
I am still using the attachment ebonding table to determine if the attachment has been sent to the 3rd party or not.
This way I can have a number of 3rd parties attached to the record and know that each has received the attachment. The issue with the other suggestions that I have seen and used as a basis are all adding a field to the sys_attachment table.
It is based on two components.
A Business Rule on the sys_attachment table
A Script Include which is called and is used to determine if this email needs to send attachments.
The Business Rule
// Initial variables
var strAdded = '';
var myRec = current.instance;
// get the members of the Recipients and create an array
var RecArr = current.recipients.split(',');
// Search the attachment table for the attachments for this record
var SAgr = new GlideRecord('sys_attachment');
SAgr.addQuery('table_sys_id',myRec);
SAgr.query();
// loop until we have checked all attachments
while (SAgr.next()) {
// for each attachment, we need to check each recipient
for (i=0;i<RecArr.length;i++)
{
// check to see if we "fullAttachmentSend" via EmailAddress
// or via the Noticification in use - we check to see if is a 3rd party Notification
if (new GroupMLongConditionList().sendAttachment(RecArr[i]) == true )
{
// check out table for this attachment and this user
uaegr = new GlideRecord('u_attachment_ebonding');
uaegr.addQuery('u_3rd_party',RecArr[i]);
uaegr.addQuery('u_attachment_sys_id',SAgr.sys_id);
uaegr.query();
//gs.log('add attachments uaegr has been queried');
// if we do not find a match, we have not sent an email
// update the table so we do not send this attachment again
if (!(uaegr.next()))
{
//gs.log('add attachments, nothing found in uaegr');
uaegr.initialize();
uaegr.u_3rd_party = RecArr[i];
uaegr.u_attachment_sys_id = SAgr.sys_id;
uaegr.insert();
// Add this attachment to a list of attachments already added
// If this attachment has not been added to this email, then add it, otherwise, why add again ?
// need this as this loops based on each recipient and if there is more than one to receive.
if (strAdded.indexOf(SAgr.sys_id) == -1)
{
var table = SAgr.table_name;
// where gr.sys_id is the sys_id on the attachment table and table = u_client_impact_record
// the line below copies all the attachments from the parent record, not the selected attachments.
//GlideSysAttachment.copy(SAgr.table_name,SAgr.sys_id,'sys_email',current.sys_id);
var SAIgr = new GlideRecord('sys_attachment');
SAIgr.initialize();
SAIgr.table_name = 'sys_email';
SAIgr.table_sys_id = current.sys_id;
SAIgr.file_name = SAgr.file_name;
SAIgr.compressed = SAgr.compressed;
SAIgr.content_type = SAgr.content_type;
SAIgr.size_byes = SAgr.size_bytes;
//SAIgr.size_compressed = SAgr.size_compressed;
SAIgr.insert();
// now we need to get over to the sys_attachment_doc table and copy each record
// that is associated with the old attachment to the new one
var SADgr = new GlideRecord('sys_attachment_doc');
var SADIgr = new GlideRecord('sys_attachment_doc');
SADIgr.initialize();
SADgr.addQuery('sys_attachment.sys_id',SAgr.sys_id);
SADgr.query();
while (SADgr.next())
{
SADIgr.data = SADgr.data;
SADIgr.length = SADgr.length;
SADIgr.position = SADgr.position;
SADIgr.sys_attachment = SAIgr.sys_id;
SADIgr.insert();
}
strAdded += SAgr.sys_id;
}
}
else
{
//gs.log('add attachments : matched a record so no send');
}
}
}
}
The script include call at line 27 was originally going to look to see if the notification was using a specific template, but I was not able to establish this, so now it is just simply passing an email address across and doing an if statement to determine if the attachment needs to be sent or not
sendAttachment : function (emailaddress) {
if(emailaddress.indexOf('@poyntz') != -1 || emailaddress.indexOf('poyntzj@outlook.com') != -1)
return true;
else
return false;
},