How to make Attachements Private or Public.

Rohant Joshi2
Kilo Expert

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.

19 REPLIES 19

Hi Christian,

Thanks for the solution. 

Could you please help me on that how can we implement private check box when we adding attachments.

Thanks,find_real_file.png

Did you see my post that was related to this?

I went through all the steps that you need.

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:

 

<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:
noAttachments.png

With attachments added to the record:
attachments.png

In both instances, if the checkbox is checked when a file is uploaded, the Private field will be set when the file attaches.

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?

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