Hi,
I am trying to create a Sharepoint List and perform CRUD operations using JSOM on a Sharepoint Online site.
However I get error as below :
===========================
Uncaught ReferenceError: SP is not defined on SP.SOD.executeFunc("sp.js", CreateList());
Below is the script:
===============================
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script language="ecmascript" type="text/ecmascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="/_layouts/sp.js"></script>
<script language="javascript" type="text/javascript">
SP.SOD.executeFunc("sp.js", CreateList());
function CreateList() {
var listName = $("#lname").val();
var url = $("#lurl").val();
var siteURL= "https://abc.sharepoint.com.sites/mno";
var clientContext = new SP.clientContext(siteURL);
var web = clientContext.get_web();
var listCreationInfo = new SP.ListCreationInformation();
listCreationInfo.set_title(listName);
listCreationInfo.set_url(url);
listCreationInfo.set_templateType(SP.ListTemplateType.genericList);
var newList = web.get_lists().add(listCreationInfo);
clientContext.executeQueryAsync(onSuccess, onFailure);
}
function onSuccess() {
alert('List Created Successfully');
}
function onFailure() {
alert('Error while creating the list');
}
</script>
</head>
<body>
<table>
<tr>
<td> Enter List Name:</td>
<td><input type="text" id="lname" /></td>
</tr>
<tr>
<td>Enter List Url:</td>
<td><input type="text" id="lurl" /></td>
</tr>
<tr>
<td><input id="btnCreate" type="button" value="Create List" /></td>
</tr>
</table>
</body>
</html>
Can some one help me out here ?