0

I am deploying the script below on a SharePoint site via content editor web-part. The script works fine but it leads to the site not functioning properly and the browser console throws the following error: (e.g. the button create new site is not working).

sp.js:2 Uncaught TypeError: Cannot read property 'majorVersion' of undefined
    at sp_initialize (sp.js:2)
    at sp.js:2

I have been debugging for hours and have no idea where the error is coming from. All that im sure of is that the error must come from the script, because if it is not implemented on the page, the page works fine.

<div class="tagcloud" id="divListItems"></div>
<script type="text/javascript" src="https://SITEURL/sites/SITE/jquery-3.5.0.min.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.taxonomy.js"></script>
<script type="text/javascript">
$(document).ready(function(){   
    SP.SOD.loadMultiple(['SP.js', 'SP.Taxonomy.js'], retrieveListItems);    
});
function retrieveListItems() {
    var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('Seiten');
    var camlQuery = new SP.CamlQuery();
//      camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' +
//      '<Value Type=\'Number\'>1</Value></Geq></Where></Query><RowLimit>3</RowLimit></View>');
    this.collListItem = oList.getItems(camlQuery);
    clientContext.load(collListItem);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed));
    return
}
function onQuerySucceeded(sender, args) {
    var listItemInfo = '';
    var listItemEnumerator = collListItem.getEnumerator();
    var allLabelsArray = [];
    var allIDsArray = [];
    while (listItemEnumerator.moveNext()) {
        oListItem = listItemEnumerator.get_current();
        var objTag = oListItem.get_item('TaxKeyword').getEnumerator();
        while (objTag.moveNext()) {
            var oListItem2 = objTag.get_current()
            var label = oListItem2.get_label()
            var ID = oListItem2.get_wssId()
            allLabelsArray.push(label);     
            allIDsArray.push(ID);   
        }

    }
    Array.prototype.contains = function(v) {
        for(var i = 0; i < this.length; i++) {
            if(this[i] === v) return true;
        }
        return false;
        };
    Array.prototype.unique = function() {
        var arr = [];
        for(var i = 0; i < this.length; i++) {
            if(!arr.contains(this[i])){
                arr.push(this[i]);
            }
        }
    return arr;
    }
    var allUniqueLabelsArray = allLabelsArray.unique();
    var allUniqueIDsArray = allIDsArray.unique();
    var allUniqueLabelsArrayMD = [];
    var maxanz = 20;
    var strHTML = '';
    for(k=0;k<=allUniqueLabelsArray.length-1;k++){
        var counter = 0
        var fontSize = 0
        allUniqueLabelsArrayMD[k]=[]
        for(l=0;l<=allLabelsArray.length-1;l++){
            var arrUniqueTag = allUniqueLabelsArray[k];
            if(arrUniqueTag == allLabelsArray[l]){
                    counter = counter + 1                                           
            }
        }           
        if (counter <=7){
            fontSize = counter * 10
        }
        else{
            fontSize =70
        }
        allUniqueLabelsArrayMD[k].push([arrUniqueTag],[fontSize],[allUniqueIDsArray[k]])
        allUniqueLabelsArrayMD.sort(function(a,b){
            return b[1] - a[1];
        });     
        allUniqueLabelsArrayMD = allUniqueLabelsArrayMD.slice(0,maxanz)
        function Shuffle(o) {
            for (var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
            return o;
        };
        Shuffle(allUniqueLabelsArrayMD);
    }   
    for (m=0;m<=Math.min(maxanz-1,allUniqueLabelsArrayMD.length-1);m++) {   
        var strLink='https://SHAREPOINTURL/sites/SITENAME/SITE-INDEX/Seiten/A-Z.aspx#InplviewHash659a3ffb-a8df-49a9-bf07-28faae26f7a5=WebPartID%3D%7B1130C38D--9082--4597--966D--41D7EA9DFA81%7D-FilterField1%3DTaxKeyword-FilterValue1%3D'+allUniqueLabelsArrayMD[m][2]+'-FilterOp1%3DIn-FilterLookupId1%3D1'                                                                                                                                          
        if(strHTML == ''){
            strHTML = '<span style="font-size: '+allUniqueLabelsArrayMD[m][1]+'px; line-height: 1.1;"> <a href='+strLink+ ' target="_blank"> '+allUniqueLabelsArrayMD[m][0]+'</a></span>'
        }
        else{
            strHTML =strHTML + '<span style="font-size: '+allUniqueLabelsArrayMD[m][1]+'px; line-height: 1.1;"> <a href="'+strLink+'" target="_blank"> '+allUniqueLabelsArrayMD[m][0]+'</a></span>'
        }           
    }
    //Displaying the output in a DIV
    $("#divListItems").html(strHTML);
    return
}
function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() +'\n' + args.get_stackTrace());
    return
}
</script>
0

Your JS file load order is wrong. You should load sp.runtime.js before sp.js.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.