SharePoint Tips and Scripts

When you need to innovate, you need collaboration.  — Marissa Mayer

Have you ever needed a column is a list to be required based on a value chosen in another column? This can be done using the Validation Settings on the list. List validation allows you to check that a user has entered valid data or has entered all necessary data. This type of validation should be done at the list level. At the column level, a validation formula cannot refer to another column. To add more than one validation see additional instructions below. Let's take the following scenario as an example to understand how this works. A user is filling out a status report. A standard question is "Do you have any deliverables due this week?" You want to make sure that if the user selects 'Yes', then you want to require them to list the deliverables that were due and their due dates. Create your columns: For this example I created the following two columns: "Deliverables" and "DeliverableDue". Just like that no spaces or special characters. This is to follow column naming best practices. You can go back and rename them and add a description after you have setup the validation rule. Also note that if you have a multiple lines of text column, you will need to first create it as a single-text column and change it to multi after the validation settings have been created. Here is the formula you would use for your validation: =IF([Deliverables]="Yes",IF([DeliverableDue]"",TRUE,FALSE),TRUE) Let's break down the formula so we can understand what it's doing.

  1. The bold portion of the formula is checking to see if the value of Deliverables is equal to 'Yes': =IF([Deliverables]="Yes",IF([DeliverableDue]"",TRUE,FALSE),TRUE)
  2. If this validation passes and the selected value is Yes, then the next bolded portion of the formula ensures that DeliverableDue contains data. =IF([Deliverables]="Yes",IF([DeliverableDue]"",TRUE,FALSE),TRUE)
Here are the steps to set up your validation:
  1. Navigate to your List Settings and select Validation settings under the General Settings heading.
  2. On the Validation settings page where you can enter the above formula as well as a message you want to provide to your users if the validation check fails. Enter the formula in the Formula column and enter your message in the User Message column.
  3. Select Save.
validation settings So now when a user selects 'Yes' for Deliverables and attempts to select 'Save', they will not be allowed to and will be presented with the user message: validation settings

To conditionally require data in more than one SharePoint column

To add an additional conditionally required field, you will need to use a nested if statement using the AND function and the ISBLANK function. You can write out your statement in Excel to make sure you get the syntax written correctly. Here is the formula you will use: =IF(AND(ISBLANK(DeliverableDue)=TRUE,Deliverable="Yes"),FALSE,IF(AND(ISBLANK(ListIssues)=TRUE,Issues="Yes"),FALSE,TRUE)) To continue our example from above, let's say there are now two scenarios:
  1. Are there deliverables due?
  2. Are there any critical issues to address?
Create the columns as instructed above. You may want to change the column description validation settings validation settings

Scenario: Sometimes you may need to limit the character length of a multiline text column to a certain number of characters. You can achieve this functionality using a Jquery script. Follow below steps to implement this functionality.

  1. Create a column with Data Type “Multiline Text” and select the plain text option.
  2. Copy the below script and save it as a .js file.
  3. If your column has a different name other than “Description” you will need to modify the script and replace “Description” with your column name.
  4. You will also need to update the alert message and replace “Your message…” with your own message that you want displayed when a user tries to enter more than the number of characters you set.
  5. Save the file to your Site Assets library.
  6. Since this script references the jquery-1.10.2.min.js file, you will need to download it and save it to the Site Assets library as well.
  7. Open the NewForm.aspx page for the list and add a Content Editor web part at the top of the page. You will also need to do this on the EditForm.aspx page.
  8. Edit the Content Editor web part and add a link to this script file.
  9. Save the page(s) and test entering text into the multi-line text box.
<script src=”/SiteAssets/JS/jquery-1.10.2.min.js” type=”text/javascript”></script> <script type=”text/javascript”> $(function(){ $(“textarea[title$=’Description’]”).keyup(function(){ var txtValue = $(“textarea[title$=’Description’]”).text(); if(txtValue.length > 200){ alert(“Your message…”); $(“textarea[title$=’Description’]”).val(txtValue.substring(0,199)); } }); });</script>

If you want to map a SharePoint Document Library or List in Windows File Explorer so that you can access the files through Windows Explorer instead of through your browser follow the steps below. The Open with Explorer link is not available in the SharePoint List ribbon so you will have to follow the manual process listed below.

To map to a SharePoint Document Library:

    1. Navigate to the document library using Internet Explorer browser.
    2. Select the LIBRARY tab.
    3. Select the Open with Explorer link in the Connect & Export group in the Ribbon.
    4. When File Explorer opens, right click the Quick Access link in the left pane, then click Pin current folder to Quick Access.
    The documents in the document library can be accessed using Windows File Explorer the same way as you would in SharePoint.

    To map to a SharePoint List:

      1. Navigate to the SharePoint List using Internet Explorer browser.
      2. Copy the URL up to the end of the list name but not "AllItems.aspx".
      3. NOTE: If there are %20 characters in the URL, replace them with spaces as explorer will not know what to do with them.

      4. Open Windows File Explorer.
      5. Paste the URL into the file path field and then Enter.
      6. Double click on the Attachments folder.
      7. Right click the Quick Access link in the left pane, then click Pin current folder to Quick Access.

      Each list item is assigned a number and the documents that are attached to the list items can be found in a folder with the corresponding number.

Here are some examples of scripts I've used in designing SharePoint pages.

Hide SharePoint Page Title

  1. Create a CSS file with the following entry and upload it to the site in an accessible place (Site Assets library, for example):
  2. 
    #pageContentTitle {display:none !important;}
    
  3. Add the Content Editor Web Part somewhere on the page.
  4. Click the down arrow, ‘Edit Web Part’, and under ‘Content Link’ enter the URL of the CSS file you uploaded. You may also want to set the ‘Chrome’ of the Web Part to ‘none’.
  5. Click ‘Ok’, save the page and title should now be gone.
  6. Duplicate this step on any pages that you want the page title removed.

Remove padding on web part page.


       .cell-margin {margin-top: 10px;margin-bottom: 10px;}
       .tableCol-75 {padding-right: 15px; Width: 75% !Important;}
       .tableCol-25 {Width: 25% !Important;}
       .tableCol-50 {Width: 50% !Important;}
       .ms-table .tableCol-50:first-child {padding-right: 15px;}
       .tableCol-33 {padding-left: 15px;Width: 33% !Important;}
       .ms-table .tableCol-33:first-child {padding-left: 0px;}

Hide Quick Launch/Navigation Menu on left to maximize page content.


#s4-leftpanel {display: none}
.s4-ca {margin-left: 0px}

Hide the "Recently Modified" on wikis


.s4-recentchanges{display:none;}

Hide the "I Like It" and "Tags & Notes" icons on the ribbon


.ms-socialNotif-Container {display:none;}

Wrap Promoted Tiles


 .ms-promlink-body {width:100%}
 .ms-promlink-header {visibility:hidden}

Limit Max Characters in Multi Line Text Column

Scenario: Sometimes you may need to limit the character length of a multiline text column to a certain number of characters. You can achieve this functionality using a Jquery script. Follow below steps to implement this functionality.
  1. Create a column with Data Type “Multiline Text” and select the plain text option.
  2. Copy the below script and save it as a .js file.
  3. If your column has a different name other than “Description” you will need to modify the script and replace “Description” with your column name.
  4. You will also need to update the alert message and replace “Your message…” with your own message that you want to be displayed when a user tries to enter more than the number of characters you set.
  5. Save the file to your Site Assets library.
  6. Since this script references the jquery-1.10.2.min.js file, you will need to download it and save it to the Site Assets library as well.
  7. Open the NewForm.aspx page for the list and add a Content Editor web part at the top of the page. You will also need to do this on the  EditForm.aspx page.
  8. Edit the Content Editor web part and add a link to this script file.
  9. Save the page(s) and test entering text into the multi-line text box.

/SiteAssets/JS/jquery-1.10.2.min.js
<script type="text/javascript">
$(function(){
  $("textarea[title$='Description']").keyup(function(){
   var txtValue = $("textarea[title$='Description']").text();
   if(txtValue.length > 200){
    alert("Your message...");
    $("textarea[title$='Description']").val(txtValue.substring(0,199));
   }
  });
});
</script>