Monday 29 August 2016

Best practises for creating a SharePoint Workflow


1.  Nomenclature for workflow names:

  • While developing one major workflow give some prefix to this.

                Ex- “W1- Workflow name”

  • If any workflow dependent on this workflow or relates to this workflow, then  give the same continued prefix to these workflows too.

                Ex- “W2- Workflow name-1”, “W2- Workflow name-2”…

  • Continue till all the inter related workflows are not completed.
  • If you encounter a completely new independent workflow then give some new prefix to that.

               Ex- “New1- workflow name”

2.  At the beginning of creating new workflow, give some meaningful name and description  to the workflow. Description is needed when someone on later point of time wants to review/update the workflows.

3.  Mention logs for every workflow step / any condition / action. This will make the debugging of  the workflow easier. You can see the logs in the bellow path-
     Select the list item -> list -> click on workflow
     
     Maintain a log in every starting of step. 
     Ex- Entered to step 1 (If step name is step 1)

4.  If workflow is creating very large number of records then put some condition in the workflow  which will archive the record/ copy the record to other list if status is closed/completed/…

     Because admin has to set the threshold for number of list items. In central admin, admin can change the threshold. But if not possible also or if threshold is fixed to 5000 or some value like this, developer can configure such things in workflow.
    
     Click here to see how to archive list contents.

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.