Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Creating a List using JSOM shows error Uncaught ReferenceError: SP is not defined

$
0
0

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 ?


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>