I spent lot of time to figure this out but did not find anything,
    function constructAgenciesData() {       
        $.ajax({
           url: "getAgenciesAndGlobalJson.do",
               dataType: "json",
           success: function(data){
            $.each(data, function (index, row) { 
                  // console.log("data : "+ JSON.stringify(data));
                   $("#"+row.id).data("assignedAgencies", row.assignedAgencies).data("restOfAgencies", row.restOfAgencies).data("global", row.global).data("globalID", row.globalID);      
                  });    
                }        
         });  
   } 
   constructAgenciesData();
   $(function($){ 
      $(".globalswitch").each(function () {
         var idRow = $(this).parents('tr')[0].id;
         alert(idRow);
         console.log($('#'+idRow).data("global"));// <-- UNDEFINED
        $(this).switchButton({
            checked: row.data("global") 
        });
    });
     $(document).on('click','button.btn', function () {     
        var idRow = $(this).parents('tr')[0].id;  
        var title = $(this).parents('td:first').siblings(':eq(1)').text();
        title = "Rule Name :  " + title;
        $("#divPopUp").data('param_1', idRow);
        $("#divPopUp").data('opener', this).dialog("option", "title", title).dialog("open");
        console.log($('#'+idRow).data("global"));// <-- WORKING
        var old_array = $('#'+idRow).data("restOfAgencies"); 
        var new_array = $('#'+idRow).data("assignedAgencies"); 
        addCheckbox(diff(old_array,new_array));
    });
    });
I don't know why the same line :
console.log($('#'+idRow).data("global"));
is undefined in the .each function.
BUT it is working in the click function .
 
     
    