function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Erica CoxErica Cox 

Need to perform action if particular subtab is open

I have the need to disable the buttons on a page if a particular subtab is open in a certain state, as indicated in the URL of the subtab.  The code below works sometimes, but only if that tab happens to be last in the list.  The return statement here doesn't break the loop, because it just returns from the callback. Tried setting a var in the for loop and doing the disable code after the loop if the var was true, but but that doesn't work because getPageInfo is asynchronous. 
var evalSubTabIdsCallback = function (result) {
         	if(result.ids != null) {
         		var arrTabIds = result.ids;
         		var arrLength = arrTabIds.length;         		
         		
         		for(var i = 0; i <arrLength ; i++) {
         			var tabId = arrTabIds[i];
         			sforce.console.getPageInfo(tabId,function(pageInfoResult){         				
         				var JSONObj = JSON.parse(pageInfoResult.pageInfo);         				
         				var url=JSONObj["url"];
         				if( url.indexOf('addingFromCase=true') > 0 )  { 
						    buttonsEnabled(false);
        					gIsScreenDisabled = true;
        					return;        						     						
        				
        				} else {
							buttonsEnabled(true);
        					gIsScreenDisabled = false;         					      				
         				}         					
         			});    			         			
         		}        
         	}
         	  
         };
        
         var focusedCaseTabListener = function (result) {
         	var primaryTabId = null;
                sforce.console.getSubtabIds(primaryTabId , valSubTabIdsCallback);                 

         };