How to make Attachements Private or Public.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2014 07:23 AM
Hello,
I have a requirement to make attachments to a form as public or private. I have added a checkbox on attachement form named "Is Private file".At the time of attachement if I check the check box, this attachement is private and should be visible to only ITIL and admins. If I dont check this check box by default this attachement will be public and visible to all.
I have tried this on demo019. But I dont find way to proceed to make this functionality work.
Can anyone guide me on that.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2020 11:56 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2020 02:33 AM
Did you see my post that was related to this?
I went through all the steps that you need.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2023 11:59 AM
Hi Christian.
I've been using this for a while now, and have created an "extension" perse, that will allow uploading of attachments as Private before adding files, so that business rules can query whether or not an attachment was added privately or not.
To do this, you will need to:
1. Edit the attachment UI Page:
- The id for this page is: sys_ui_page.do?sys_id=b1b390890a0a0b1e00f6ae8a31ee2697
- In the HTML for the page:
- You will need to add HTML elements in 2 places:
1. On line 138, underneath the `loadFileXml` button:
- You will need to add HTML elements in 2 places:
<button class="btn btn-primary" onclick="document.getElementById('loadFileXml').click()">${gs.getMessage('file_attach')}</button>
<!-- Line above is included for location clarity purposes, edits start below -->
<br></br>
<br></br>
<input id="no_attach_upload_private_cb"
title="Attachment will not be visible to non-agents."
type="checkbox"
style="vertical-align: -2px; margin-right: 10px;"
onchange="handlePrivateChanged(this)">
</input>
<label for="no_attach_upload_private_cb"
title="Attachment will not be visible to non-agents.">
Upload as private
</label>
2. On line 181, below the "Attach" input:
<input style="display:none;" disabled="true" class="attachfile-attach button" id="attachButton" type="submit" value="${gs.getMessage('Attach')}" />
</td>
<!-- Lines above included for location clarity, edits start below-->
<td id="privateFileAttach" colspan="3">
<input id="upload_private_cb"
title="Attachment will not be visible to non-agents."
type="checkbox"
style="vertical-align: -2px; margin-right: 10px;"
onchange="handlePrivateChanged(this)">
</input>
<label for="upload_private_cb"
title="Attachment will not be visible to non-agents.">
Upload as private
</label>
</td>
- In the Client Script of the UI Page, you will need to add the following script:
function handlePrivateChanged(checkbox){
//Set the value of the other (sibling) checkbox to the new value
var otherEl;
if(checkbox.id == 'upload_private_cb') otherEl = document.getElementById('no_attach_upload_private_cb');
else otherEl = document.getElementById('upload_private_cb');
otherEl.checked = checkbox.checked;
//Get the form so that we can change the submission criteria
var formElement = document.getElementById('sys_attachment');
var baseAction = 'sys_attachment.do?sysparm_record_scope=$[jvar_parent_record_scope]'; //The default HTML "action" value
formElement.action = baseAction + (checkbox.checked ? '&u_private=true' : '')
}
- You will also need to create a new Business Rule:
- Table: sys_attachment
- Advanced: true
- When: before
- Insert: true
- Advanced:
- Script:
(function executeRule(current, previous /*null when async*/) {
//If there is
if(gs.action && gs.action.getGlideURI()){
//Look for if there is a u_private=true in the URI
if(gs.action.getGlideURI().toString().indexOf('u_private=true') > -1)
current.u_private = true;
}
})(current, previous);
The end result of all of this is the following:
With no attachments added to the record:
With attachments added to the record:
In both instances, if the checkbox is checked when a file is uploaded, the Private field will be set when the file attaches.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2023 08:56 AM
Hello David!
First of all, thanks for your contribution!
I've implemented your suggestions but when tick 'Upload as private' before the file choose nothing happens. I mean, I tick 'Upload as private', choose a random file, attach it to the incident but it isn't marked as private.
Could you help me understand what is missing, please?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2023 09:13 AM
Hi Diogo,
My extension is also reliant on Henrik's field, ACL, and Client Script extension, which he explains fully in this reply thread on this post.
If you are still having issues after implementing these, please make sure everything from all three posts (Christian's, Henrik's and mine) are implemented correctly, and gather any log files relating to errors.
-David