1. Create a Separate page in SharePoint site and a content editor Webpart.
2. Upload the JavaScript code to site Assests and copy the link.
3. Edit the CEWP and add the path of the script txt file and save it.
4. Enter the list name and click the create list button and refresh the page.
5. The list created in SharePoint site.
Code:
- <script
- src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"
- type="text/javascript">
- </script>
- <script
- type="text/javascript"
- src="/_layouts/15/sp.runtime.js">
- </script>
- <script
- type="text/javascript"
- src="/_layouts/15/sp.js">
- </script>
- <button onclick="createList()">Create List</button>
- <input type="text" id="listnme" name="Enter the List Name" size="20">
- <script type="text/javascript">
- var siteUrl = 'https://thegowtham.sharepoint.com/teams/GT';
- function createList() {
- var clientContext = new SP.ClientContext(siteUrl);
- var oWebsite = clientContext.get_web();
-
- var listCreationInfo = new SP.ListCreationInformation();
- var olist=document.getElementById("listnme").value;
- listCreationInfo.set_title(olist);
- listCreationInfo.set_templateType(SP.ListTemplateType.genericList);
-
- this.oList = oWebsite.get_lists().add(listCreationInfo);
-
- clientContext.load(oList);
- clientContext.executeQueryAsync(
- Function.createDelegate(this, this.onQuerySucceeded),
- Function.createDelegate(this, this.onQueryFailed)
- );
- }
-
- function onQuerySucceeded() {
- var result = oList.get_title() + ' created.';
- alert(result);
- }
-
- function onQueryFailed(sender, args) {
- alert('Request failed. ' + args.get_message() +
- '\n' + args.get_stackTrace());
- }
-
- </script>