Monday 29 August 2016

Solution for creating multiple Attachment column in SharePoint list

Requirement:



On click of the colour icons it should open a file in a new tab.  As many as such columns can be created using following process. 

Steps:

1. Create column of type"Choice".   Name it "Status".   Add Values "Red", "Yellow", "Green".

2. Create a calculated column. Name it "SW".  Add the below calculation.

-----------------------------------------------------------------------------------------
   ="<a href='#'  class='SW_status_id'>
<DIV style='font-weight: bold; font-size:50px;v-align:top;color:"&(IF(Status="Red","Red",IF(Status="Yellow","Yellow",IF(Status="Green","Green"))))&";'>•</DIV>
</a>"
-----------------------------------------------------------------------------------------
                                                            
Note:  
The above calculation will set an ID for each item for SW column. And also it will change thecolour for every status change in "Status" column.

3.  Edit the page, and add a content editor web part.

4. Create a file and add the below JQuery script in that file. 

-----------------------------------------------------------------------------------------
// download the "jquery-1.11.3.min.js" and upload in SharePoint doc library.Give that file path 
// here.
<script src="https://<site path>/Test_DoC_lib/jquery-1.11.3.min.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function(){
$('.SW_status_id').click(function(){
  
//get the id of column where we are clicking on SW colour icon.
  var id =$(this).closest('tr').attr('iid').split(',')[1];

  window.open("https://<site path>/Lists/Test_AddAttachments_list/Attachments/" + id + "/My_excel_file.xlsx");
}); 

$('.HW_status_id').click(function(){
  
 //get the id of column where we are clicking on SW colour icon.
  var id =$(this).closest('tr').attr('iid').split(',')[1];
  
  window.open("https://<site path>/Lists/Test_AddAttachments_list/Attachments/" + id + "/Test_Excel_template.xlsx");
});

});
</script>
-----------------------------------------------------------------------------------------

Note: 
The URL for accessing any file in the attachment column for any list is:
"https://<Site url till lists folder>/<list name>/Attachments/" + id + "/< file name with extension>"

5.  Upload this file in a document library.

6. Get this file path from the document library and set this path in the content editor web part.

7. Save and publish.


Now work is done !!!


Thank You.



No comments:

Post a Comment