Thursday, October 8, 2015

Hide the Content Types based on Document Set Title in SharePoint Library Using JavaScript

Steps for Implementation
Create a Site Content Types Navigate Site Settings>>Site Content Types>>Click on Create
Click on OK Go to Library >> Library Settings >> Click on Document Set
Click on Document Set Settings and move HR Policy to Right side box
Click on OK then the content types will be added to library
So please add all other content types which is use for your business requirement using the above steps Hide the Relevant Content Types.
Get the Content Type ID from browser using the below screenshot

Add the below script into the page using Content Editor Webpart

<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("hideContentType");
function hideContentType(){
$("a.ms-cui-ctl-a2 ").live('click', function (event) {
var documentSetTitle = $('div[id="idDocSetPropertiesWebPart"]').children()[0];
documentSetTitle = documentSetTitle.innerText;
$('li[class="ms-cui-menusection-items"]').css("display", "none");
if(documentSetTitle.indexOf("HR") > -1)
{
$('a[id="Ribbon.Document.All.NewDocument.Menu.ContentTypes.1-Menu32"]').parents('li').css("display", "");
$('a[id="Ribbon.Document.All.NewDocument.Menu.ContentTypes.0-Menu32"]').parents('li').css("display", "none");
$('a[id="Ribbon.Document.All.NewDocument.Menu.ContentTypes.5-Menu32"]').parents('li').css("display", "none");
}
if(documentSetTitle.indexOf("IT") > -1)
{
$('a[id="Ribbon.Document.All.NewDocument.Menu.ContentTypes.0-Menu32"]').parents('li').css("display", "");
$('a[id="Ribbon.Document.All.NewDocument.Menu.ContentTypes.5-Menu32"]').parents('li').css("display", "none");
$('a[id="Ribbon.Document.All.NewDocument.Menu.ContentTypes.1-Menu32"]').parents('li').css("display", "none");
}
if(documentSetTitle.indexOf("Operations") > -1)
{
$('a[id="Ribbon.Document.All.NewDocument.Menu.ContentTypes.5-Menu32"]').parents('li').css("display", "");
$('a[id="Ribbon.Document.All.NewDocument.Menu.ContentTypes.1-Menu32"]').parents('li').css("display", "none");
$('a[id="Ribbon.Document.All.NewDocument.Menu.ContentTypes.0-Menu32"]').parents('li').css("display", "none");
}
});
}
</script>

No comments:

Post a Comment