- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2022 02:27 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2022 02:34 AM - edited ‎10-26-2022 02:38 AM
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);
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>
I Hope this helps.
Please mark this helpful if this helps and Accept the solution if this solves your issue.
Regards,
Kamlesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2022 04:28 AM - edited ‎10-25-2022 04:29 AM
Hi @Nikhil55 ,
Below is the way to achieve this:
1. Create a Display BR that will fetch all the attachments attached to the record. I am using incident table for this example.
(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())
files += attachGr.getValue("file_name") + ",";
g_scratchpad.filesUploaded = files;
})(current, previous);
2. Create a UI page, where you will be fetching data sent by display BR and will use to create a dynamic content having all the attached file's name.
<?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 : "";
var message = "";
ele = document.getElementById('attachments_uploaded');
if(files != ""){
var fileNames = files.split(",");
fileNames.forEach(function(fName){
message += fName + "<br/>";
})
}
ele.innerHTML = message
</script>
</j:jelly>
You can modify the HTML/CSS of the page as per your need, I am helping here how to get the data and show on form.
3. Finally write a client callable UI action and call this UI page on click of it
function showAttachment() {
var x = new GlideModal("attachments");
x.setTitle("Attachments List");
x.render();
}
Now open any incident record and click on the Show Attachments button, it will popup list of all attachments, attached with the opened record.
I Hope this helps.
Please mark this helpful if this helps and Accept the solution if this solves your issue.
Regards,
Kamlesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2022 08:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2022 08:35 AM
Hi @Nikhil55 ,
You have to create UI page with the name attachments first as shown in the screen shot below:
Below is the ui page script used:
<?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 : "";
var message = "";
ele = document.getElementById('attachments_uploaded');
if(files != ""){
var fileNames = files.split(",");
fileNames.forEach(function(fName){
message += fName + "<br/>";
})
}
ele.innerHTML = message
</script>
</j:jelly>
I Hope this helps.
Please mark this helpful if this helps and Accept the solution if this solves your issue.
Regards,
Kamlesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2022 10:50 PM
Hi @kamlesh kjmar , Thank you! I can see the list of attachments. but I want the file names as a link so that when I click on the file I can able to open that document and view. Is there any way to achieve that?