10

I wonder how do I keep the navigation bar of the parent site when I create a subsite. Below is the code I'm using to create the subsite and thought it might be some parameter that I could use to do that.

The code I am using works and the subsite are created correctly but not with the parent navigation bar.

Any idea? Thanks.

jQuery.ajax({
    url: siteUrl + "/_api/web/webinfos/add",
    type: "POST",
    data: JSON.stringify(
        {
            'parameters': {
                '__metadata': { 'type': 'SP.WebInfoCreationInformation' },
                'Url': urlName,
                'Title': title,
                'Description': description,
                'Language': 1046,
                'WebTemplate': template,
                'UseUniquePermissions': false
            }
        }
    ),
    headers: {
        "accept": "application/json; odata=verbose",
        "content-type": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val()
    },
    success: function (data) {

    },
    error: function (data, errorCode, errorMessage) {

    }
});

Edited: Example code to change UseShared. It works, I get the alert success but nothing changes.

$.ajax({
    url: siteUrl + "/_api/Web/Navigation/UseShared",
    type: "POST",
    data: JSON.stringify({ 'UseShared': true }),
    headers: {
        "X-HTTP-Method": "MERGE",
        "accept": "application/json;odata=verbose",
        "content-type": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val(),
        "IF-MATCH": "*"
    },
    success: onSuccess,
    error: onError
});
function onSuccess(data) {
    alert("Pass request.");
}
function onError(errorMessage) {
    alert("Erro = " + errorMessage);
}
  • Did you find a solution? After we changed the masterpage using REST, the UseShared settings is somehow set to false. We really like to reapply shared navigation after the masterpage is set. – user33124 Sep 4 '14 at 19:27
  • No I dont, sorry. – Douglas Santos Sep 11 '14 at 17:05
3

According to the scalar properties to SP.WebInfoCreationInformation there is no parameter for that. The available properties are the ones you use. So you'll probably have to make another call after the web is created, and set the UseShared in Microsoft.SharePoint.Client.Navigation to true.

| improve this answer | |
  • Hi Anders, thanks for the reply. You can show an example code how can I do that? – Douglas Santos Jun 26 '14 at 13:59
  • I try a code (updated in post) but nothing change and I have no response from my request. What is wrong? – Douglas Santos Jun 26 '14 at 18:59
  • Hey, tbh I'm not sure whats wrong. If you could use the CSOM instead of rest, this would be much easier. Did a quick search, and checked the docs. But could not find much on REST and Navigation – Anders Aune Jun 30 '14 at 6:05
  • I update the code above with my request. Now he make the request and I got the response but not change... – Douglas Santos Jun 30 '14 at 13:27
1

After some researches, here is the solution... Using the "old" JSOM

var context = new SP.ClientContext("YOUR SITE URL");
var currentWeb = context.get_web();
var navigation = currentWeb.get_navigation();
navigation.set_useShared(true);
context.executeQueryAsync(function () { alert("Navigation Modification Successful"); });
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.