Category Archives: SharePoint Online

Microsoft Flow – Make SharePoint Library Unique

This guide is to help admins & end users make libraries unique through Flow. There are a few ways to do this however, some rely on Azure to complete, the route I’ll show only requires Owner permissions to the SharePoint site.

First we’ll need to make the library unique by breaking inheritance, then we can assign the permissions using the REST API

  1. Within Microsoft Flow, add an action called ‘Send an HTTP request to SharePoint’
  2. Enter the Site Address (https://domain.sharepoint.com/sites/IT/
  3. Set the Method as POST
  4. URI = _api/web/lists/getByTitle(‘Documents’)/breakroleinheritance
  5. Ensure to change the library in brackets to your own library, the ‘Documents’ library is the out of the box library provided when a site is created

To assign permissions to the library through Flow, this can be achieved by adding another HTTP request.

Add another HTTP request and copy the below. This will get the membership of the Owners group in SharePoint. When a site is created, by default the owners group will always have an ID of 3, the members group has an ID of 5.

Set the Method as “GET’ & the URI as ‘_api/web/sitegroups(3)”

Add a third and final HTTP request to add the Owners group to the library. Set the Method as ‘POST’ & the URI as “_api/web/lists/getByTitle(‘Documents’)/roleassignments/addroleassignment(principalid=3,roledefid=1073741829)”

Note the following:
The principalid is the ID of the group
The roledefid for Owner permissions is 1073741829
The roledefid for Contribute permissions is 1073741827
The roledefid for Read permissions is 1073741826
The roledefid for Design permissions is 1073741828
The roledefid for Edit permissions is 1073741830
The roledefid for View Only permissions is 1073741924

Hide certain Lookup Values from appearing on New or Edit forms

I’ve recently had an issue where there are over 2,000 items in a lookup and trying to search for the one you want was a huge pain, the code below can find certain text in the lookup options and exclude these, doing so reduces the amount of values you see and more user friendly for the end users.

From the script below, ‘Electronic Device’ was my column name, which also was a required field. The term I was looking for was “OLD” (as old devices were no longer required and therefore flagged old).

Remember to download the JQuery CDN.

<script type=”text/javascript” src=”https://TENANT.sharepoint.com/sites/YourSharePointSiteCol/SiteAssets/CDN/jquery-3.3.1.min.js”></script>
<script>

$(document).ready(function(){
$(“select[Title=’Electronic Device Required Field’]”).find(‘option:contains(“OLD”)’).remove();
});

</script>

 

Prevent selection of Lookup values on save

When you have a Lookup column you may find some results you don’t want your end users to select, for instance in my example below, the column name is ‘Team Name’ which is also a required field. This column basically shows every single team.

What the script below does is prevents the user from saving the form if “Human Resources” or “–Select a Team–” have been chosen. It also provides text under the specific column to show an error message “Please select a different Team”. (last section of the code below to see where to place this).

The code below can be amended to be a Choice column rather than a lookup by changing the getTagFromIdentifierAndTitle(“select”,”Lookup”,”Team Name Required Field”); to your column.

<script>

function getTagFromIdentifierAndTitle(tagName, identifier, title) {
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
if (tags[i].title == title && (identifier == “” || tempString.indexOf(identifier) == tempString.length – len)) {
return tags[i];
}
}
return null;
}

function PreSaveAction(){
var oTeamName = getTagFromIdentifierAndTitle(“select”,”Lookup”,”Team Name Required Field”);
var blockName = oTeamName.options[oTeamName.selectedIndex].text;

if(blockName.indexOf(‘–Choose a Team–‘)==0||blockName.indexOf(‘Human Resources’)==0){
alert(“Please select a different Team”);
$(“#tname-error”).text(“Please select a different Team”);
return false;
}
return true;
}

</script>

<td width=”400px” valign=”top” class=”ms-formbody”>
<SharePoint:FormField …….
<span id=”tname-error”></span>
<SharePoint:FieldDescription ……

Details below of the tags & identifiers per column type

Column Type Tag Identifier
Single Line of Text input text
Multiple Line of Text input textarea
Lookup select Lookup