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.