Hi there,
I worked for few items in the client object model using ECMA script and here are the sample codes I am sharing for the example.
The below code gives you the web title and web id.
The below code adds the new list to the site with updating the list title, description, template and then added to the web,
I worked for few items in the client object model using ECMA script and here are the sample codes I am sharing for the example.
The below code gives you the web title and web id.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
ExecuteOrDelayUntilScriptLoaded(getWebSiteData, "sp.js"); | |
var context = null; | |
var web = null; | |
function getWebSiteData() { | |
context = new SP.ClientContext.get_current(); | |
web = context.get_web(); | |
context.load(web); | |
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod)); | |
} | |
function onSuccessMethod(sender, args) { | |
alert('web title:' + web.get_title() + '\n ID:' + web.get_id()); | |
} | |
function onFaiureMethodl(sender, args) { | |
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace()); | |
} </script> |
The below code adds the new list to the site with updating the list title, description, template and then added to the web,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/ecmascript"> | |
ExecuteOrDelayUntilScriptLoaded(createList, "sp.js"); | |
function createList() { | |
var clientContext = new SP.ClientContext.get_current(); | |
var oWebsite = clientContext.get_web(); | |
var listCreationInfo = new SP.ListCreationInformation(); | |
listCreationInfo.set_title('COMList1'); // list name | |
listCreationInfo.set_description('description'); // list description | |
listCreationInfo.set_templateType(SP.ListTemplateType.genericList); //list type | |
oWebsite.get_lists().add(listCreationInfo); | |
clientContext.executeQueryAsync( | |
Function.createDelegate(this, this.onQuerySucceeded),// when success | |
Function.createDelegate(this, this.onQueryFailed) // when failed | |
); | |
} | |
function onQuerySucceeded() { | |
alert("List Created"); | |
} | |
function onQueryFailed(sender, args) { | |
alert("List Failed"); | |
}</script> |