samedi 28 février 2015

SharePoint 2013 JavaScript CSOM: How to change the field 'PublishingPageLayout'



I am trying to update the page layout of a wiki page using the JavaScript object model and I can't seem to get it to work.


I know I need to do something like this:



pageItem.set_item('PublishingPageLayout': 'url of the .aspx layout file');


When I set the url, the url shows under the page's 'Page Layout' field, but the page itself does not reflect the change. Please help


EDIT:


When I think about this more, when I create the page using the JavaScript object model, the page that is created is not using the default layout. When I try to manually change the page layout of the page, the 'Page Layout' icon in the ribbon is greyed and inaccessible. Perhaps this is the root of the problem. The code I use to create the page is as follows:



function createWikiPage(webUrl,listTitle,fileName,success, failure)
{
getListUrl(webUrl,listTitle,
function(listUrl){

var fileUrl = listUrl + '/' + fileName
var url = webUrl + "/_api/web/GetFolderByServerRelativeUrl('" + listUrl + "')/Files" +
"/AddTemplateFile(urlOfFile='" + fileUrl + "',templateFileType=1)";
$.ajax({
url: url,
method: "POST",
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest" : $("#__REQUESTDIGEST").val()
},
success: function (data) {
success(data.d);

},
error: function (data) {
failure(data);
}
});

},
failure
);


}

function getListUrl(webUrl,listTitle,success, failure)
{
var url = webUrl + "/_api/web/lists/GetByTitle('" + listTitle + "')/RootFolder";
$.ajax({
url: url,
method: "GET",
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose"
},
success: function (data) {
success(data.d.ServerRelativeUrl);

},
error: function (data) {
failure(data);
}
});
}







0 commentaires:

Enregistrer un commentaire