Automatically Encrypting Attachments through Business Rule. (Encryption Support)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2020 09:24 AM
Hi,
I've been implementing the Encryption Support Plugin in our instance and it is working as expected. The requirement is that the encryption should be mandatory. I've researched around this and gotten to this post: Is there a way to make the encryption of attachments automatic, rather than a checkbox visible to th... which talks about making changes to the 'attachment' UI Page. I did this, the encryption checkbox is indeed read only and checked. But when I upload the file as an user with an encryption context, the file isn't encrypted.
So, I thought of running a BR to get this to work, so that even the user forgets to click the checkbox, this BR will automatically encrypt attachments. So here is the BR I've written:
When: After (Insert and Update)
Table: sys_attachment
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if(current.table_name == 'sc_req_item') {
var fgr = new GlideRecord('sc_req_item');
fgr.addQuery('sys_id', current.table_sys_id);
fgr.query();
if(fgr.next()) {
if(fgr.u_service_category == 'My Category') {
var contextGR = new GlideRecord("sys_encryption_context");
contextGR.addQuery("name", "Context Name");
contextGR.query();
if (!contextGR.next()) {
gs.log("*********** No such encryption context " + encryptionContextName);
}
var encryptionId = contextGR.getUniqueValue();
var sysAttachment = new GlideSysAttachment();
sysAttachment.changeEncryptionContext(current.getValue("table_name"),current.getValue("table_sys_id"),current.sys_id,encryptionId);
gs.log("*********** ENCRYPTED [" + current.sys_id + "] " + current.getValue("file_name"));
}
}
}
The problem is, this BR isn't working for some reason. I've written a similar BR on sc_req_item table and that is working perfectly, but this doesn't. I guess, this has something to do with the way attachment table name goes from sc_cart_item to sc_req_item.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2020 04:11 PM
Hello,
I'd be curious to know if you actually tested those attachments (regarding where you said you wrote one on the sc_req_item table and it's working "perfectly"). By that I mean, have you downloaded those attachments and saw that they weren't corrupted? Like...attach an img and an excel file, then download it back after you've attached it and it's "encrypted"...and do those files work properly? The image actually shows the image and not says a message like: "windows doesn't support this file" and the excel file tries to open but then says something like "can't open this file"?
I'm asking this specific question for a reason, so I'll wait to see what you say.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2020 09:27 PM
Hi Allen,
Thanks for the reply.
To answer your question, yes I have tested those attachments. I did it again, like you suggested with an image and an excel. I downloaded these same attachments and the system was able to read them properly.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2024 11:43 PM
Hi @Sanjay14 ,
I am facing a issue with encryption where attachment is not getting encrypted when end user uploads an attachment, additionally, they receive an error saying- "Unable to encrypt attachment".
Module access policies have been defined for Agents, but not for end users as there is no role for end user.
Can someone please help me debug this behaviour?