none
How To Use Sharepoint Javascript API in my web application RRS feed

  • Question

  • Hello,

    I am trying to build a website that I will later be using on Microsoft Teams with the Website tab. For this website I need to fetch information from a SharePoint list and manipulate it. I am having issues importing the Sharepoint api to my javascript code although I followed the windows tutorial on how to do so. Below I've attached the code I've used.

     <script src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js" type="text/javascript">
        </script>
        <script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js">
        </script>
        <script type="text/javascript">
            var hostweburl;
    
            // Load the required SharePoint libraries.
            $(document).ready(function () {
    
                // Get the URI decoded URLs.
                hostweburl =
                    decodeURIComponent(
                        getQueryStringParameter("SPHostUrl")
                    );
    
                // The js files are in a URL in the form:
                // web_url/_layouts/15/resource_file
                var scriptbase = hostweburl + "/_layouts/15/";
    
                // Load the js files and continue to
                // the execOperation function.
                $.getScript(scriptbase + "SP.Runtime.js",
                    function () {
                        $.getScript(scriptbase + "SP.js", execOperation);
                    }
                );
            });
    
            function initMap() {
                // The location of Uluru
                var uluru = { lat: -25.344, lng: 131.036 };
                // The map, centered at Uluru
                var map = new google.maps.Map(
                    document.getElementById('map'), { zoom: 4, center: uluru });
                // The marker, positioned at Uluru
                var marker = new google.maps.Marker({ , map: map });
            }
    
            // Function to execute basic operations.
            function execOperation() {
                // Continue your program flow here.
                retrieveAllListProperties("https://dafna.sharepoint.com/sites/TakeMe");
    
            }
    
            // Function to retrieve a query string value.
            // For production purposes you may want to use
            // a library to handle the query string.
            function getQueryStringParameter(paramToRetrieve) {
                var params =
                    document.URL.split("?")[1].split("&amp;");
    
                var strParams = "";
                for (var i = 0; i < params.length; i = i + 1) {
                    var singleParam = params[i].split("=");
                    if (singleParam[0] == paramToRetrieve)
                        return singleParam[1];
                }
            }
    
            function retrieveAllListProperties(siteUrl) {
                var clientContext = new SP.ClientContext(siteUrl);
                var oWebsite = clientContext.get_web();
                this.collList = oWebsite.get_lists();
                clientContext.load(collList);
    
                clientContext.executeQueryAsync(
                    Function.createDelegate(this, this.onQuerySucceeded),
                    Function.createDelegate(this, this.onQueryFailed)
                );
            }
    
            function onQuerySucceeded() {
                var listInfo = '';
                var listEnumerator = collList.getEnumerator();
    
                while (listEnumerator.moveNext()) {
                    var oList = listEnumerator.get_current();
                    listInfo += 'Title: ' + oList.get_title() + ' Created: ' +
                        oList.get_created().toString() + '\n';
                }
                alert(listInfo);
            }
    
            function onQueryFailed(sender, args) {
                alert('Request failed. ' + args.get_message() +
                    '\n' + args.get_stackTrace());
            }
        </script>

    I am developing on a mac. Any help please? Been stuck on this for a while.


    • Edited by A_H_K Wednesday, July 17, 2019 12:05 AM
    Wednesday, July 17, 2019 12:03 AM