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 @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

 

Hi @Nikhil55 ,

 

Is your issue resolved ? if yes, could you please help us close this thread by marking appropriate answer as helpul and accepting the solution.

 

This will help others having similar issue get proper solution.

 

Regards,

Kamlesh

Hi @Nikhil55 ,

 

This is a followup on your issue. Could you please help us close this thread by Accepting the solution, if your problem is solved.

 

Regards,

Kamlesh

Hi @kamlesh kjmar , Thank you for the solution.

Hi @kamlesh kjmar can you please provide same script for workspace ui action also?