0

I'm having issues trying to load the proper script below to become a customized image rotator on my SharePoint 2013 platform. Can anyone help please? I want to know if I am writing the code properly...

  • I am using Cycle as my jQuery base
  • I have checked the code with CamlQueryBuilder Helper tool to get the proper Camlquery

var subsiteUrl = "site/subsite"

(function($j) {
    ExecuteOrDelayUntilScriptLoaded(doWorkA, "SP.js");

    function doWorkA() {
        var currCtxA = new SP.ClientContext(subsiteUrl);
        var targetListA = currCtxA.get_web().get_lists().getByTitle("rotatorimages");

        var queryA = new SP.CamlQuery();

        queryA.set_viewXml("<View><Query><OrderBy><FieldRef Name=\"Modified\" Ascending=\"FALSE\"></FieldRef></OrderBy><Where><Eq><FieldRef Name=\"Featured\"/><Value Type=\"Integer\">1</Value></Eq></Where></Query></View>")

        listItemsA = targetListA.getItems(queryA);

        currCtxA.load(listItemsA);

        currCtxA.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));   
    }

    function on QuerySucceeded(sender, args) {
        var listItemEnumeratorA = listItemsA.getEnumerator();
        while (listItemEnumeratorA.moveNext()) {
            alert("Found matching Item! \nTitle=" +
                listItemEnumeratorA.get_current().get_item("Featured"));
        }
    }

    function onQueryFailed(sender, args) {
            alert("Request failed. " + args.get_message() +
                "\n" + args.get_stackTrace());
        }

    $(".slideshow").cycle({
        fx: "scrollUp", 
        speed: 300,
        timeout: 4700,
        random: 1
    });


})(jQuery);

2 Answers 2

0

Wrap the anonymous immediate function in a document ready function like so...

$(document).ready(function(){

var subsiteUrl = "site/subsite"

(function($j) {
    ExecuteOrDelayUntilScriptLoaded(doWorkA, "SP.js");

    function doWorkA() {
        var currCtxA = new SP.ClientContext(subsiteUrl);
...

})(jQuery);

});
0

1) Your listItemsA variable is not set as a global variable, therefor the listItemsA might not exists within your success function.

2) Because the success function an async function it will mean that your cycle method can execute before the query has been succesfully retrieved. And the slidehsow ill start without your data present I would place/execute the cycle function within the succes function once all items are created within the container of the "slideshow" class

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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