Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SP.NavigationNode.get_isVisible() broken?

I need to read the "Top Nav", the "Children Nodes" and check if each node is visible.

I am using JSOM to accomplish this. Everything is working fine except for the get_isVisible() function. It always returns true. MSDN: http://msdn.microsoft.com/en-us/library/office/jj246297.aspx

I am on a publishing site in 2013 and I know some of the items are hidden. (My web and context are defined outside of this snippet)

    var visParents = [], visChildren = [];
    var topNodes = web.get_navigation().get_topNavigationBar();
    context.load(topNodes);
    context.executeQueryAsync(onQuerySucceeded, onQueryFailed)

    function onQuerySucceeded() {
            var nodeInfo = '';
            var nodeEnumerator = topNodes.getEnumerator();
            while (nodeEnumerator.moveNext()) {
                var node = nodeEnumerator.get_current();
                nodeInfo += node.get_title() + '\n';
                if (node.get_isVisible())
                    visParents.push(node);
            }
            console.log("Current nodes: \n\n" + nodeInfo);
            console.log("Visible Parents", visParents)
    }

    function onQueryFailed(sender, args) {
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
like image 488
user3236668 Avatar asked May 12 '26 09:05

user3236668


1 Answers

It is a known issue, it seems that SP.NavigationNode.isVisible property does not correspond to the property that indicates whether navigation node is hidden or shown.

Please refer "Hidden" property of SPNavigationNode for a details

The following function demonstrates how to retrieve hidden node Urls:

function getGlobalNavigationExcludedUrls(Success,Error)
{
    var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    var subwebs = web.get_webs();
    var pagesList = web.get_lists().getByTitle("Pages");
    var pageItems = pagesList.getItems(SP.CamlQuery.createAllItemsQuery()); 
    var allProperties = web.get_allProperties();
    context.load(web);
    context.load(subwebs);
    context.load(allProperties);
    context.load(pageItems);
    context.executeQueryAsync(
        function() {
          var excludedIds = allProperties.get_item('__GlobalNavigationExcludes').split(';');  
          var exludedUrls = [];
          for (var i = 0; i < excludedIds.length - 1; i++ )
          {
              for (var j = 0; j < subwebs.get_count(); j++ )
              {
                  var subweb = subwebs.getItemAtIndex(j);
                  if(subweb.get_id().toString() == excludedIds[i]){
                      exludedUrls.push(subweb.get_serverRelativeUrl());
                      break;
                  }
              }
              for (var j = 0; j < pageItems.get_count(); j++ )
              {
                  var pageItem = pageItems.getItemAtIndex(j);
                  if(pageItem.get_item('UniqueId').toString() == excludedIds[i]){
                      exludedUrls.push(web.get_serverRelativeUrl() + pageItem.get_item('FileRef'));
                      break;
                  }
              }
          }    
          Success(exludedUrls);           
        },
        Error
    );
}

//Usage: print excluded nodes Urls
getGlobalNavigationExcludedUrls(function(excludedNodeUrls){
       for (var j = 0; j < excludedNodeUrls.length; j++ )
       {
           console.log(excludedNodeUrls[j]);
       }    
    },
    function(sender,args){
       console.log(args.get_message());
    });
like image 79
Vadim Gremyachev Avatar answered May 15 '26 02:05

Vadim Gremyachev