Site structure using JSOM

Hi,
What I am trying to do is write some Javascript that will  display A site collection on top and all its descendant sites below using JSOM.
Parent child relation ship should be indicated either by indentation or by Collapse / Expand functionality. Is this possible using JSOM?
Please help..
I have following code but this displays all subwebs as a flat structure, instead i want some sort of differentiation between a parent web and a child web.
<script type="text/ecmascript" language="ecmascript">
ExecuteOrDelayUntilScriptLoaded(runCode, "sp.js");
var webCollection = null;
function runCode() {
var clientContext = new SP.ClientContext.get_current();
if (clientContext != undefined && clientContext != null) {
var web = clientContext.get_web();
this.webCollection = web.getSubwebsForCurrentUser(null);
clientContext.load(this.webCollection);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
function onQuerySucceeded() {
var webInfo = '';
var webEnumerator = this.webCollection.getEnumerator();
while (webEnumerator.moveNext()) {
var web = webEnumerator.get_current();
webInfo += "<a class='list-group-item' title='click to navigate' href=\'" + web.get_serverRelativeUrl() + "\' target='blank'>" + web.get_title() + "</a>";
$(".list-group").append(webInfo);
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
</script>
techie

Hi,
According to your description, my understanding is that you want to display subsite with Collapse / Expand style under the root site.
I suggest you can do  some customization with Jquery and CSS to achieve it.
Here is a code snippet for your reference:
<script type="text/javascript">
// Expand/Collapse Buttons
// Feedback and questions: [email protected]
function WPToggle(thisId, ImageId)
if (document.getElementById(thisId).style.display=="none")
document.getElementById(thisId).style.display="";
document.getElementById(ImageId).src = "/_layouts/images/minus.gif";
else
document.getElementById(thisId).style.display="none";
document.getElementById(ImageId).src = "/_layouts/images/plus.gif";
function ExpandCollapseBody()
var i = 1;
var WPid = "WebPartWPQ1" ;
var WPtitleid = "WebPartTitleWPQ1" ;
var Toggleid = "ToggleImage1" ;
do
try
document.getElementById(WPtitleid).innerHTML = '<IMG id="' + Toggleid + '" onClick="WPToggle(\'' + WPid + '\',\'' + Toggleid + '\')" alt="Expand/Collapse" style="margin:6px 5px 0px 2px; float:left; cursor:pointer;" src="/_layouts/images/minus.gif" />' + document.getElementById(WPtitleid).innerHTML ;
if (document.getElementById(WPid).style.display=="none")
document.getElementById(Toggleid).src = "/_layouts/images/plus.gif";
catch(err) {}
i = i + 1;
WPid = "WebPartWPQ" + i ;
WPtitleid = "WebPartTitleWPQ" + i;
Toggleid = "ToggleImage" + i;
} while (document.getElementById(WPid))
_spBodyOnLoadFunctionNames.push("ExpandCollapseBody()");
</script>
Here is a detailed code demo, I suggest you can take a look for reference:
http://blog.pathtosharepoint.com/2008/10/25/expandcollapse-buttons-for-your-web-parts/
Best Regards
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Zhengyu Guo
TechNet Community Support

Similar Messages

  • Using other site structure storage instead on index.portal

    Hi.
    The question is quite simple. All data about WebLogic portal structure is stored in index.portal XML file. Are there any ways to move data storage from this XML to database, actually to force portal to retrive data about site structure and portlets on pages from database?
    Thanks for all responces.

    Maksim Galushka wrote:
    The question is quite simple. All data about WebLogic portal structure is stored in index.portal XML file. Are there any ways to move data storage from this XML to database, actually to force portal to retrive data about site structure and portlets on pages from database?Yes, use the Portal Administration Tool to create a streaming desktop from the
    .portal file. A streaming desktop is stored in the database so that it can be
    modified and changed at runtime.
    Gerald

  • How to get anonymous guest link "View Only" and "Edit" URL using JSOM or Search API ?

    Hi,
    I need to get list item anonymous guest link View Only and
    Edit URLs (as shown in image below) using JSOM or SharePoint 2013
    Search API.
    the URL will be like this - https://<site URL>/_layouts/15/guestaccess.aspx?guestaccesstoken=yRaYGmE9n
    Any one has any idea how to do achieve this?
    Thanks
    Shakir

    Hi Shakir,
    To get the anonymous guest link “View Only”, we can use SP.ObjectSharingInformation.anonymousViewLink property in sp.js.
    https://msdn.microsoft.com/en-us/library/office/jj246826.aspx
    To get the anonymous guest link “Edit”, we can use SP.ObjectSharingInformation.anonymousEditLink property in sp.js.
    https://msdn.microsoft.com/en-us/library/office/jj246468.aspx
    We can also use REST API to get the guests links:
    _api/web/Lists/getbytitle('library name')/items(item id)/GetObjectSharingInformation?$expand=SharedWithUsersCollection&retrieveAnonymousLinks=true
    Thanks,
    Victoria
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Creating publishing page in specific folder and with custom page layout using JSOM

    Hi!
    I have a site collection under my root, in which I have a page library with a folder inside. I want to create a publishing page inside the folder using JSOM. The API provides the following information on the three possible ways of how you can create a publishing
    page.
    PublishingPageInformation with all defaults.
    PublishingPageInformation.Name and PublishingPageInformation.PageLayoutListItem.
    PublishingPageInformation.Name, PublishingPageInformation.PageLayoutListItem and PublishingPageInformation.Folder.
    Source - SP.Publishing.PublishingPageInformation Properties (sp.publishing)
    Since I want to create the page in a specific folder in the page library, I have to go for the last option.
    I have a function call chain that look as follows:
    getLanguageID(webUrl, languageID)
    .then(function(resolveVal) {
    language = resolveVal;
    return checkPageExist();
    .then(getEditorialNewsFolderJSOM)
    .then(getAssociatedPageLayoutListItem)
    .then(addPublishingPage)
    The first two methods, 
    getEditorialNewsFolderJSOM
    getAssociatedPageLayoutListItem
    fetches the required data as SP.Folder- and SP.ListItem-objects.
    The problem occurs when
    addPublishingPage
    is called. This method, in turns calls this function. 
    var pageInfo = new SP.Publishing.PublishingPageInformation();
    pageInfo.set_name(publishPage.title);
    pageInfo.set_pageLayoutListItem(pageLayoutListItem);
    pageInfo.set_folder(editorialNewsFolder);
    pageCreationContext.newPage = pubWeb.addPublishingPage(pageInfo);
    clientContext.load(pageCreationContext.newPage);
    clientContext.executeQueryAsync(function() {
    publishPage.isPageCheckOut = true;
    resolve();
    }, function(error) {
    reject(precio.intranet.resource.errCreateContent_addPublishPage);
    The error happens when this function is called with the page information object.
    SP.Publishing.PublishingWeb.addPublishingPage(pageInformation)
    Error:
    Cannot read property '$2t_0' of undefined
    and it happens in SP.Runtime.js.
    I've tried this
    sample code from the MSDN-team, and added the pagelayout and folder properties, but it renders the same error.
    Creating a page directly in the page library with a blank SP.PublishingPageInformation object works perfectly fine!
    What could possibly be wrong? The error isn't something that I can debug myself since it happens in SP.Runtime.js, and the documentation for this is very sparse!
    Any help on how to resolve this issue would be helpful!

    Hi Vinay,
    This may be useful:
    https://blogs.oracle.com/jdevotnharvest/entry/remote_task_flow_vs_wsrp

  • Building the site structure for a dynamic website with JSF

    Hi,
    I am still a JSF-beginner.
    I try to build a fully-functional base-demo-application with a fix and a dynamic part.
    Fix part for menu, dynamic part for site-content.
    At the moment, the JSF-hyperlinks of the main menu work, but any JSF-parts in the included documents of the dynamic part are not shown. I guess, this is dued to inclusion of subviews, but I cannot find any similar examples in the web to come one step further.
    Here my complete demo:
    faces-config.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
    "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
    <faces-config xmlns="http://java.sun.com/JSF/Configuration">
    <navigation-rule>
    <from-view-id>*</from-view-id>
    <navigation-case>
    <from-outcome>site1</from-outcome>
    <to-view-id>/site1.jsp</to-view-id>
    <redirect>
    </redirect>
    </navigation-case>
    </navigation-rule>
    <navigation-rule>
    <from-view-id>*</from-view-id>
    <navigation-case>
    <from-outcome>site2</from-outcome>
    <to-view-id>/site2.jsp</to-view-id>
    <redirect>
    </redirect>
    </navigation-case>
    </navigation-rule>
    </faces-config>
    web.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <context-param>
    <param-name>com.sun.faces.verifyObjects</param-name>
    <param-value>false</param-value>
    </context-param>
    <context-param>
    <param-name>com.sun.faces.validateXml</param-name>
    <param-value>true</param-value>
    </context-param>
    <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
    </context-param>
    <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <session-config>
    <session-timeout>
    30
    </session-timeout>
    </session-config>
    <welcome-file-list>
         <welcome-file>
    index.jsp
    </welcome-file>
    </welcome-file-list>
    </web-app>
    index.jsp:
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <% response.sendRedirect("/jsfportal/site1.jsf"); %>
    site1.jsp:
    <?xml version="1.0" encoding="UTF-8" ?>
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <% String site = "1"; %>
    <%@ include file="base.jsp" %>
    dynamic_site1.jsp:
    <h1>Welcome to site 1</h1>
    Have fun visiting our portal
    site2.jsp:
    <?xml version="1.0" encoding="UTF-8" ?>
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <% String site = "2"; %>
    <%@ include file="base.jsp" %>
    dynamic_site2.jsp:
    <h1>Welcome to site 2</h2>
    Go to site 1: *<!-- And this is the JSF-link that is NOT shown: -->*
    <f:view>
    <h:form>
    <h:panelGrid border="0" columns="0">
    <h:commandLink id="p1" action="site1" value="Site 1" />
    </h:panelGrid>
    </h:form>
    </f:view>
    base.jsp:
    <%@ page language="java" %>
    <%@ page import = "java.io.*" %>
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <%
    String title = "";
    int siteInteger = 0;
    String dynamic_site = "";
    if ( site != null )
    if (
    ( site.length ( ) > 0 )
    ( site.length ( ) <= 30 )
    if ( isNumeric ( site ) )
    siteInteger = Integer.valueOf ( site ).intValue ( );
    switch ( siteInteger )
    case 2: title = "Site 2";
    dynamic_site = "dynamic_site2.jsp";
    break;
    default:
    title = "Site 1";
    dynamic_site = "dynamic_site1.jsp"; // Start page
    %>
    <html xmlns="http://www.w3.org/1999/xhtml"
    lang="de" xml:lang="de">
    <head>
    <title>
    <%= title %>
    </title>
    <meta name="description" content="test site" />
    <meta name="keywords" content="test site" />
    </head>
    <body>
    <div width="100%" style="text-align:left">
    <table width="970" border="0" cellspacing="0" cellpadding="0" style="background-color:#ffffaa;margin-top:25px;">
    *<!-- this is not good style putting CSS directly into HTML but it is a demo now ;) -->*
    <colgroup>
    <col width="970" />
    </colgroup>
    <tr>
    <td valign="top" align="left" style="padding:25px;">
    +<h1>+
    JSF portal
    +</h1>+
    </td>
    </tr>
    </table>
    <table width="970" border="2" cellspacing="0" cellpadding="0" style="background-color:#f5f5f0">
    <colgroup>
    <col width="270" />
    <col width="700" />
    </colgroup>
    <tr>
    <td valign="top" align="left" style="padding:25px; padding-left:40px;padding-bottom:320px;">
    <f:view>
    <h:form>
    <h:panelGrid border="0" columns="0">
    <h:commandLink id="p1" action="site1" value="Site 1" />
    <h:commandLink id="p2" action="site2" value="Site 2" />
    </h:panelGrid>
    </h:form>
    </f:view>
    </td>
    <td valign="top" align="justify" class="haupttext" style="padding:24px;">
    <p align="justify">
    <f:subview id="subview1">
    <jsp:include page="<%= dynamic_site %>" flush="true">
    <jsp:param name="" value="" />
    </jsp:include>
    </f:subview>
    </p>
    </td>
    </tr>
    </table>
    </div>
    </body>
    </html>
    <%!
    public boolean isNumeric ( String myInput )
    if (myInput == null || myInput.length() < 1)
    return false;
    int start = 0;
    if (myInput.charAt(0) == '-')
    start = 1;
    for(int i = start; i < myInput.length(); i++)
    if (!Character.isDigit(myInput.charAt(i)))
    return false;
    return true;
    %>
    Who can name me that code positions responsible for that the JSF link in the dynamic part is not shown?
    It is not that it does not work it is not shown. The JSF tree seems to be cut because of wrong use of view and subview etc.
    (To put view tags in site1.jsp and site2.jsp does not help.)
    (Once having afforded an example it should go... (*Then* with JSTL, external CSS, etc. ;) )
    Dynamical site structure with include files is the big problem at the moment.)
    bye, Maik

    I found your following suggestions for such cases (seems you are the only profound JSF freak in the world...? :-) )
    Switch between subviews in one main page
    http://balusc.blogspot.com/2007/01/dynamic-jsf-subviews.html
    But the main problem for me is that I never find complete examples, but always fragments and it would be important for a beginner to have at least once a complete JSF example over a few subviews, especially here where it is very easy to corrupt the internal tree.
    (Some examples use the subview tags in the calling JSP, some in the called e.g.... Does not matter where to put it? Some use verbatim tags for HTML code outside JSF, some don't... and so on)
    Can anyone give me an URL for a complete example of a JSF site (with all files as possible, I am not very patient, too, but in this case it makes sense to have it entire ;-) ) with dynamic switches of subviews as preferentially used for bigger portal sites?

  • Retrieve taxonomy terms maintaining the hierarchy(sub terms) using JSOM

    I believe the title is self explanatory .
    I've tried SPServices but it results in to many round trips as the number of terms and sub-terms increases.
    THe whole idea behind using term set it to set up an Global Navigation (having sub menus )across site collections.

    Please find the below links
    http://sharepoint.stackexchange.com/questions/103430/sharepoint2013-taxonomy-get-all-child-term-of-a-specific-parent-term-using-jsom
    http://sharepoint.stackexchange.com/questions/78514/accessing-terms-in-term-store-using-jsom-in-sharepoint-2013
    http://cann0nf0dder.wordpress.com/2013/04/09/accessing-taxonomy-term-store-with-jsom/

  • Get most popular user using JSOM

    Hi,
    I have a requirement to show "Employee of the month" on my intranet portal. The data has to be collaborated from 1 site collection and communities, blogs under it.
    The logic behind this can be any one option from the below. 
    1. User who has most followers
    2. User who has done maximum number of posts
    3. User having most mentions
    Iterating through all users in a site collection and getting their data seems a bit complex and performance issue might arise.
    Any help is appreciated.Thanks
    sunny

    Hi,
    According to your post, my understanding is that you want to get most popular user using JSOM.
    Per my knowledge, you need to get and count the followers for each users and and then get the max number.
    The appropriate user is the most popular user.
    To get the followers of a specific, you can refer to:
    SharePoint 2013: How to Get Following and Followers of
    User by using JSOM or JavaScript
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • Search query not able to find node under a specific site structure (eg. 2013/05)?

    Hi,
        We are saving our data on a node under year/month site structure, eg. (2013/05/node1) but when we search for the data using a query in a custom workflow., it does not fetch any results.The query being fired is something like :
       SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/content/hm/NewsroomSection/en/NewsRoom/NewsroomDetails/2013/05/node1]) .
       On trying to run this query directly in crxde, it shows no result. But when we change the site structure to 2013/5/node1, it is able to fetch results.
       I am not sure if the problem is because of the '0' digit in the month in site structure (2013/05).
       Please provide your input if any of you have come across something like this before ..
    Thanks
    Abhishek

    Hi Abhishek,
    In case of nodes with numbers, any node starting with 0, this 0 gets omitted in the search query.
    So, if your node name is like 02013 for year, when it searches it omits 0 and searches for 2013.
    In case you want to search for your node, your SQL2 query should be like below:
    SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE(['/content/mysite/en/products/2013/05'])
    See screenshot for reference. This should return you the results.
    Hope this helps.
    I guess for more reference on SQL2 queries, you can refer to JCR 2.0 spec.
    http://www.day.com/specs/jcr/2.0/6_Query.html
    Also, you might want to look at the railroad diagrams and some examples from Jackrabbit's test cases:
    http://www.h2database.com/jcr/grammar.html
    http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/resources/or g/apache/jackrabbit/spi/commons/query/sql2/test.sql2.txt?view=markup
    Hope this helps.

  • Quickly Plan your Site Structure | Adobe Muse Feature Tour | Adobe TV

    Set up your site structure and website layout quickly, by adding and arranging pages with easy-to-use visual site planning tools.
    http://adobe.ly/I5cQoN

    It would be great to get an explanation of child and sibling pages - what do they do, what's the difference, etc.

  • Set rating settings in Sharepoint library using JSOM api.

    Is it possible to set rating settings in Sharepoint library using JSOM api/ Client side?
    Ashish Baranwal || To know what you know and what you do not know, that is true knowledge

    HI,
    Please check the below url for reference.
    https://social.msdn.microsoft.com/Forums/office/en-US/5069c9b8-7427-4749-bd98-cfc0f492c3a2/how-to-enable-ratings-on-sharepoint-list-using-client-object-model-for-office-365-sharepoint-site?forum=sharepointdevelopment
    https://samlman.wordpress.com/2015/03/02/how-to-use-csom-with-ratings-in-sharepoint-2013/
    Don't forget to mark it as an Answer if it resolves your issue and Vote Me as helpful if it useful.
    Mahesh

  • Nested site navigation using Web Page Composer (WPC)

    Is it possible to nest navigation nodes using Web Page Composer?
    I have created a WPC site and added pages, but I am required to create a node with sub-pages (similar to adding a folder to a workset) for a site.
    Has anyone done this or know how to easily do this?  I do not want to maintain a separate WPC site (and corresponding workset folder) for each navigation node/group in the structure hierarchy.
    This is an example of what we are trying to accomplish in our navigation structure using a single WPC site:
    * Page 1
    * Page 2
    + Group 1
        * Page 3
        * Page 4
    + Group 2
        * Page 5
        * Page 6
    * Page 7
    Thanks in advance...
    Points will be awarded for helpful answers.

    Hi Angie,
    Could you please guide how to make the RSS link lists work in WPC, we do not receive any updates from external websites.
    Thanks,
    Shravs

  • Quickly Plan your Site Structure | CS6 & Creative Cloud Feature Tour for Design | Adobe TV

    Set up your site structure and website layout quickly, by adding and arranging pages with easy-to-use visual site planning tools.
    http://adobe.ly/Ms4x9j

    Also would be nice if you let everyone know how to export from Animate as this might be confusing. You need the OAM file when placing in Muse or Dreamweaver, to get that, you will have to go into your publish settings in Animate and check Animate Deployment Package... Hope this is helpful...

  • Event reciever using JSOM

    Hello,
    Does anybody know how to triger events for SharePoint 2010 list using JSOM? The operations what I need to implement:
    1. Copy list items from list A to list B (when new item in A list is created)
    2. Copy list items from list B to list A (when new item in B list is created)
    Thanks.

    hi
    if you copy list items using custom action (e.g. in ribbon or in context menu) with custom js handler, then you may add additional JSOM as well as any other javascript code to your custom js handler. They will work like javascript event receiver in this
    case. But of course they won't be triggered if list items will be copied using some other way, e.g. from site manager.
    Another idea which you may try is to implement regular server side event receiver which will open some page with js code which will run your JSOM even receiver. But this approach looks strange. Also it won't work for async even receivers because they are
    running in different process.
    Blog - http://sadomovalex.blogspot.com
    Dynamic CAML queries via C# - http://camlex.codeplex.com

  • How do I add video to be hosted directly on my MUSE site without using a third party site like Vimeo / You tube etc ?

    How do I add video to be hosted directly on my MUSE site without using a third party like Vimeo / You tube etc ?

    Hi,
    You can consider html video tag to do this. You will need to add it in Muse using, Object-insert as html. Detailed instructions can be viewed here
    HTML video Tag

  • I just downloaded the new version of Firefox and now every site I used to use such as Facebook, Twitter, and Youtube show "This Connection Is Untrusted"

    I just downloaded the new version of Firefox and now every site I used to use such as Facebook, Twitter, and Youtube show "This Connection Is Untrusted". Even when I do accept the risks the site no longer looks the way it's looked for years. Twitter doesn't even give me the option to accept the risks at all and shows this error (Error code: sec_error_unknown_issuer). I've tried resetting Firefox, I've checked the time and date, and I've removed and added Firefox to see if that would work. Nothing seems to be working so I can see the sites the way they normally would be instead of "coded". Can anybody help me please?!!! Thanks

    ok, unfortunately the fiddler2.com issuer in certificates might be a sign of unwanted software present on your pc that is intercepting secure network traffic. please go into the system control panel and uninstall programs like BrowserSafeguard, BrowserSafe, SafeGuard or other software that sounds suspicious and didn't get installed by you intentionally.
    <sub>reference: https://support.mozilla.org/en-US/questions/982532#answer-520145</sub>
    afterwards, run a full scan of your system with different security tools like the [http://www.malwarebytes.org/products/malwarebytes_free free version of malwarebytes] & [http://www.bleepingcomputer.com/download/adwcleaner/ adwcleaner].
    [[Troubleshoot Firefox issues caused by malware]]

Maybe you are looking for