UI action to show list of attachments attached to a form

Nikhil55
Tera Contributor

Can anyone provide UI action script to show list of attachments attached to the form. The functionality will be same as OOB paper clip attachment button present in every form but this ui action should not provide options to users to remove/add attachments. it will just show list of attachments and when clicked on attachment it should open so that user can read it.

1 ACCEPTED SOLUTION

Hi @Nikhil55 ,

 

For this you will have to modify your display BR and UI page both. Make the below mentioned changes :

 

1. Modify your display Business rule as shown below:

 

 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var files = [];
	
	var attachGr = new GlideRecord("sys_attachment");
	attachGr.addQuery("table_sys_id",current.getUniqueValue());
	attachGr.query();
	while(attachGr.next()){
		var info = {};
	info.file_name = attachGr.getValue("file_name");
	info.link = attachGr.getLink();
	files.push(info);
	}
	
	g_scratchpad.filesUploaded = JSON.stringify(files);
	

})(current, previous);

 

kamleshkjmar_0-1666776779296.png

 

2. Modify the UI page as shown below:

 

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<div id="attachments_uploaded">
	
	</div>
	<script>
		var files = g_scratchpad.filesUploaded !="" ? g_scratchpad.filesUploaded : "";
		files = JSON.parse(files);
		var message = "";
		ele = document.getElementById('attachments_uploaded');
	//alert(files)
	if(files != ""){
		//var fileNames = files.split(",");
		files.forEach(function(fName){
			//console.log(fName)
		message += "<a href ="+fName.link + " >" +fName.file_name + "</a>"+"<br/>";
		
		
		})
	}
		//alert(message)
		ele.innerHTML = message
	</script>
</j:jelly>

 

kamleshkjmar_1-1666776835039.png

 

 

kamleshkjmar_0-1666777116637.png

 

I Hope this helps.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh

 

View solution in original post

10 REPLIES 10

Hi Kamlesh

 

I have the same requirement but need to show these attachments with the checkbox besides it and when we check those checkboxes need to copy these attachments to the other table record. Could you please guide me on this? I'm able to get the attachments but when trying to use with checkboxes, it is not showing the result as expected.