Quantcast
Channel: SharePoint Legacy Versions - Using SharePoint Designer, InfoPath and Other Customizations Forum
Viewing all articles
Browse latest Browse all 2319

how to update page path and name using JavaScript

$
0
0

hi friends 

how to update path and name property of a publishing page using javascript

var contextPage;
var webPage;
var pubweb;
var pageInfo;
var newPage;
var listItem;

function pageCreate(){
	SP.SOD.executeFunc('SP.js','SP.ClientContext',loadFun);
}
function loadFun(){

	contextPage = new SP.ClientContext.get_current();
	webPage= contextPage.get_web();
	pubweb= SP.Publishing.PublishingWeb.getPublishingWeb(contextPage,webPage);
	contextPage.load(webPage);
	contextPage.load(pubweb);
	contextPage.executeQueryAsync(onQuerySuccedPage, onQueryFailedPage);
}
function onQuerySuccedPage(){

	pageInfo = new SP.Publishing.PublishingPageInformation();
	//pageInfo.set_name('test1159.aspx');
	newPage = pubweb.addPublishingPage(pageInfo);	
	contextPage.load(newPage);
	contextPage.executeQueryAsync(onPageCreate, onQueryFailedPage);	
}
function onPageCreate(){	
	alert('page created');	
	listItem = newPage.get_listItem();
    contextPage.load(listItem);
    contextPage.executeQueryAsync(onQueryUpdate, onQueryFailedPage);    
}

function onQueryUpdate(){

	listItem.set_item('Title', 'text page 1210');

// update the page name property it is not working 
	listItem.set_item('Name','text1210.aspx');


	listItem.update();

	contextPage.executeQueryAsync(OnUpdateSuccess, OnUpdateFailed);
}

function onQueryFailedPage(){
	alert('failed');
}
function OnUpdateSuccess(){
alert('done');
}

function OnUpdateFailed(){
alert('failed');
//alert(args.get_message());
}

if i am using "listItem.set_item('Name','text1210.aspx');" it is not working is there any other way to change page Name


Viewing all articles
Browse latest Browse all 2319

Trending Articles