Applies To: SharePoint Online and SharePoint On-Premises
Description:
By default, the portal quick links are visible for all the users. If we need to show particular quick link only to users present in a SharePoint group, we need to configure a script for the quick link to achieve this.
Summary of Steps:
- Create the required quick link in the Portal site. Please refer instructions to create the quick link to auto populate with certain category and issue type from #3 in https://www.crowcanyon.help/article/197/
- Configure custom script to show/hide for the users present in the SharePoint group.
Detailed Steps:
After the Portal quick tile is configured in the Portal settings, we can configure a custom script for the required tile to achieve this feature. Please go to the Portal site –> Portal settings–> Home Page Settings –> Quick Links –> Edit the required quick link –> Click on “Custom JavaScript” –> enter the below script in the script function and click on Ok and save the settings. See sample screenshots below
Script:
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + '/_api/web/currentuser/?$expand=groups',
method: "GET",
contentType: "application/json;odata=verbose",
headers: {
"Accept": "application/json;odata=verbose"
}
}).done(function(data)
{
var groupNames = ['SharePoint Group Name'];
var userGroups = data.d.Groups.results;
var foundInGroups = userGroups.filter(function(g){ return groupNames.indexOf(g.LoginName) > -1});
if(!foundInGroups || foundInGroups.length == 0){
$("#" + paramTileInfo.Guid).remove();
}else{
functionCallback(paramTileInfo);
}
})
.fail(
function(error){
console.log(JSON.stringify(error));
functionCallback(paramTileInfo);
})
Note: Please specify the required SharePoint group name in the above script at “Var groupNames” variable so the quick link appears in the portal only for the members present in this SP group.
Additional Information:
– If we need to show this tile to multiple SharePoint Groups, then replace the “Var groupNames” variables in the script like below
– var groupNames = [‘SharePoint Group Name’,’Other SharePoint Group Name’];