Convert JSOM code to synchronous RRS feed

  • Question

  • have the JSOM script to get data from a SharePoint list on my page of different countries in different DIV, i am calling the function in document.ready as many number of times as there are number of countries,

    but i have an alert just before i call the function and if i remove the alert(country_list[i]) code does not work.

    How can i fix this?

    <script type="text/javascript">
        var country_list = ["Belgium", "Brazil","Canada", "Germany","USA", "Other countries"];
        for(var i=0; i<country_list.length; i++)
    //if i remove this alert the code does not work
            if ($('.accordion_body').is(':visible')) {
    function retrieveListItems_berba(country) {
        var clientContext = new SP.ClientContext.get_current();
        var oList = clientContext.get_web().get_lists().getByTitle('xyz');
        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name=\'Country\' /><Value Type=\'Choice\'>"+ country +"</Value></Eq></Where></Query>" + 
        this.collListItem = oList.getItems(camlQuery);
            Function.createDelegate(this, this.onQuerySucceeded), 
            Function.createDelegate(this, this.onQueryFailed)
    function onQuerySucceeded(sender, args) {
        var counter = 1;
        var LiTextCountry = '';
        var listItemInfo = '';
        var listItemEnumerator = collListItem.getEnumerator();
        while (listItemEnumerator.moveNext()) {
            var oListItem = listItemEnumerator.get_current();
            var ContactName= oListItem.get_item('ContactName')
            var Title= oListItem.get_item('Title'); 
            var Country= oListItem.get_item('Country');
            var image= oListItem.get_item('Image').get_url(); 
            var ULIDCountry= document.getElementById(Country+counter);
            LiTextCountry = "<div class='media-left'><img src='" + image + "' class='media-object' style='width:60px'></div>" +
                      "<div class='media-body'><h4 class='media-heading'>" + ContactName +"</h4><span>" + Title + "</span>"+
             ULIDCountry.innerHTML = LiTextCountry;
    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + 
            '\n' + args.get_stackTrace());




    • Moved by Bill_Stewart Wednesday, December 13, 2017 5:13 PM Move to more appropriate forum
    Wednesday, December 13, 2017 12:42 PM

All replies