+ Start a Discussion
raj kiranraj kiran 

Service cloud sub tabs not opening

I have strange issue, the below is my code which when executed in production and full copy sandbox the sub tabs are not opening. the wired part is that if I test the same in developer org it is working fine. Both the orgs have same code except for some alert message.
functionality : When service cloud users creates case and saved, it will redirect to detail page. On the detail page we are presenting some url to open. the code for opening the url is below.
Isuse : When user creates case and clicks on the first time link is not getting opened. but if the same case closed and reopned, the links works fine.
I need to understand why it is not working for the first time?

 
<apex:page standardController="Case">
    <A HREF="#" onClick="testOpenSubtab();return false">Detailed KB Search</A> 
    <apex:includeScript value="/support/console/22.0/integration.js"/>
    <script type="text/javascript">
        function testOpenSubtab(kb, sub) {
            //First find the ID of the primary tab to put the new subtab in
           sforce.console.getEnclosingPrimaryTabId(openSubtabNew);
alert("hi");
        }

        var openSubtabNew = function openSubtabNew(result) {
            //Now that we've got the primary tab ID, we can open a new subtab in it
            var primaryTabId = result.id;
            kb = "{!Case.KB_Product_URL__c}";
            sub = "{!Case.Subject}";
            var knowledgebaseurl;
            var category_type;
            var category_Value;
            category_type = "{!Case.Case_Type__c}" + " " +  "{!Case.Problem_symptom__c}"
           //alert(category_type);
            switch (category_type) {
               case 'Administration Initial Setup / Configuration' :  category_Value = 'c/4694,4707/kw/'; break;
                case 'Administration No Value' :  category_Value = 'c/4694,0/kw/'; break;
                case 'Administration Page Layout' :  category_Value = 'c/4694,4705/kw/'; break;
                case 'Administration User Administration' :  category_Value = 'c/4694,4706/kw/'; break;
                case 'Answer Lists and Trees No Value' :  category_Value = 'c/6045,0/kw/'; break;
                case 'Application Add Documents' :  category_Value = 'c/4692,4697/kw/'; break;
                case 'Application Coversheet' :  category_Value = 'c/4692,4698/kw/'; break;
                case 'Application Document List' :  category_Value = 'c/4692,4699/kw/'; break;
                case 'Application Email Link' :  category_Value = 'c/4692,4700/kw/'; break;
                case 'Application Error Code' :  category_Value = 'c/4692,4701/kw/'; break;
                case 'Application No Value' :  category_Value = 'c/4692,0/kw/'; break;
                case 'Bulletin Control Packages No Value' :  category_Value = 'c/584,0/kw/'; break;
                case 'Compatibility Testing No Value' :  category_Value = 'c/4033,0/kw/'; break;
                case 'Depot Repair Controller Board' :  category_Value = 'c/2566,2569/kw/'; break;
                case 'Depot Repair FCU' :  category_Value = 'c/2566,2571/kw/'; break;
                case 'Depot Repair No Value' :  category_Value = 'c/2566,0/kw/'; break;
                case 'Depot Repair Operation Panel' :  category_Value = 'c/2566,2568/kw/'; break;
                case 'Depot Repair Power Supply' :  category_Value = 'c/2566,2567/kw/'; break;
                case 'Developer Tools No Value' :  category_Value = 'c/588,0/kw/'; break;
                case 'Document Solutions Adaptec' :  category_Value = 'c/846,871/kw/'; break;
                case 'Document Solutions Doculex PDF Capture' :  category_Value = 'c/846,848/kw/'; break;
                case 'Document Solutions Documentum' :  category_Value = 'c/846,857/kw/'; break;
                case 'Document Solutions iManage' :  category_Value = 'c/846,858/kw/'; break;
                case 'Document Solutions ISIS' :  category_Value = 'c/846,899/kw/'; break;
                case 'Document Solutions Kofax Ascent Capture' :  category_Value = 'c/846,847/kw/'; break;
                case 'Document Solutions Kofax Ricochet' :  category_Value = 'c/846,859/kw/'; break;
                case 'Document Solutions No Value' :  category_Value = 'c/846,0/kw/'; break;
                case 'Document Solutions PixView' :  category_Value = 'c/846,911/kw/'; break;
                case 'Document Solutions Quantum Snap Server' :  category_Value = 'c/846,849/kw/'; break;
                case 'Document Solutions Rimage' :  category_Value = 'c/846,852/kw/'; break;
                case 'Documentation Cost Fact Sheets' :  category_Value = 'c/746,984/kw/'; break;
                case 'Documentation Installation Guides' :  category_Value = 'c/746,747/kw/'; break;
                case 'Documentation Licensing Info' :  category_Value = 'c/746,1013/kw/'; break;
                case 'Documentation Marketing Literature' :  category_Value = 'c/746,956/kw/'; break;
                case 'Documentation No Value' :  category_Value = 'c/746,0/kw/'; break;
                case 'Documentation Operator Manuals' :  category_Value = 'c/746,596/kw/'; break;
                case 'Documentation Parts Manuals' :  category_Value = 'c/746,957/kw/'; break;
                case 'Documentation Pricing' :  category_Value = 'c/746,985/kw/'; break;
                case 'Documentation Product Specifications' :  category_Value = 'c/746,797/kw/'; break;
                case 'Documentation Product Support Guides' :  category_Value = 'c/746,958/kw/'; break;
                case 'Documentation Release Notes' :  category_Value = 'c/746,960/kw/'; break;
                case 'Documentation RTB' :  category_Value = 'c/746,1216/kw/'; break;
                case 'Documentation Service Manuals' :  category_Value = 'c/746,959/kw/'; break;
                case 'Documentation Technical Information' :  category_Value = 'c/746,4155/kw/'; break;
                case 'Documentation Warranty Information' :  category_Value = 'c/746,614/kw/'; break;
                case 'Documentation White Papers' :  category_Value = 'c/746,583/kw/'; break;
                case 'Drivers/Utilities Camera Drivers' :  category_Value = 'c/581,988/kw/'; break;
                case 'Drivers/Utilities CD/DVD Drivers' :  category_Value = 'c/581,987/kw/'; break;
                case 'Drivers/Utilities LAN Fax Drivers' :  category_Value = 'c/581,809/kw/'; break;
                case 'Drivers/Utilities No Value' :  category_Value = 'c/581,0/kw/'; break;
                case 'Drivers/Utilities Print Drivers' :  category_Value = 'c/581,876/kw/'; break;
                case 'Drivers/Utilities Scanner Drivers' :  category_Value = 'c/581,862/kw/'; break;
                case 'Drivers/Utilities Scanner Drivers' :  category_Value = 'c/581,862/kw/'; break;
                case 'Drivers/Utilities Utilities' :  category_Value = 'c/581,1217/kw/'; break;
                case 'Emulator No Value' :  category_Value = 'c/1134,0/kw/'; break;
                case 'Enhancement Request No Value' :  category_Value = 'c/1172,0/kw/'; break;
                case 'Firmware Firmware Updates' :  category_Value = 'c/807,585/kw/'; break;
                case 'Firmware Firmware Subscriptions' :  category_Value = 'c/807,590/kw/'; break;
                case 'Firmware No Value' :  category_Value = 'c/807,0/kw/'; break;
                case 'GKM Support Best Practices' :  category_Value = 'c/5507,5523/kw/'; break;
                case 'GKM Support Common Questions' :  category_Value = 'c/5507,5517/kw/'; break;
                case 'GKM Support Documentation' :  category_Value = 'c/5507,5511/kw/'; break;
                case 'GKM Support GKM General' :  category_Value = 'c/5507,5508/kw/'; break;
                case 'GKM Support Master Lists' :  category_Value = 'c/5507,5525/kw/'; break;
                case 'GKM Support No Value' :  category_Value = 'c/5507,0/kw/'; break;
                case 'GKM Support Programs & Tools' :  category_Value = 'c/5507,5524/kw/'; break;
                case 'Global Asset No Value' :  category_Value = 'c/6492,0/kw/'; break;
                case 'Hot Topics No Value' :  category_Value = 'c/3349,0/kw/'; break;
                case 'How to Authentication/Password' :  category_Value = 'c/2574,4156/kw/'; break;
                case 'How to Counters/Meters' :  category_Value = 'c/2574,4624/kw/'; break;
                case 'How to Device Management' :  category_Value = 'c/2574,4163/kw/'; break;
                case 'How to Document Server' :  category_Value = 'c/2574,4176/kw/'; break;
                case 'How to Fax' :  category_Value = 'c/2574,696/kw/'; break;
                case 'How to Maintenance' :  category_Value = 'c/2574,2576/kw/'; break;
                case 'How to Networking' :  category_Value = 'c/2574,4175/kw/'; break;
                case 'How to No Value' :  category_Value = 'c/2574,0/kw/'; break;
                case 'How to Print' :  category_Value = 'c/2574,2577/kw/'; break;
                case 'How to Programming/Operation' :  category_Value = 'c/2574,582/kw/'; break;
                case 'How to Projection' :  category_Value = 'c/2574,6102/kw/'; break;
                case 'How to Scan' :  category_Value = 'c/2574,2578/kw/'; break;
                case 'How to Serial Number Locator' :  category_Value = 'c/2574,4623/kw/'; break;
                case 'How to Setup/Install' :  category_Value = 'c/2574,594/kw/'; break;
                case 'How to Video Conferencing' :  category_Value = 'c/2574,6101/kw/'; break;
                case 'Internal Support No Value' :  category_Value = 'c/975,0/kw/'; break;
                case 'Internal Support ROL' :  category_Value = 'c/975,974/kw/'; break;
                case 'Key/Signature Request Beta Signature' :  category_Value = 'c/970,4417/kw/'; break;
                case 'Key/Signature Request Demo Signature' :  category_Value = 'c/970,1141/kw/'; break;
                case 'Key/Signature Request Development Key' :  category_Value = 'c/970,972/kw/'; break;
                case 'Key/Signature Request Maintenance Signature' :  category_Value = 'c/970,4418/kw/'; break;
                case 'Key/Signature Request No Value' :  category_Value = 'c/970,0/kw/'; break;
                case 'Key/Signature Request Production Signature' :  category_Value = 'c/970,971/kw/'; break;
                case 'MFD Error Code' :  category_Value = 'c/4693,4704/kw/'; break;
                case 'MFD No Value' :  category_Value = 'c/4693,0/kw/'; break;
                case 'MFD Scanning' :  category_Value = 'c/4693,4702/kw/'; break;
                case 'MFD Software Installation' :  category_Value = 'c/4693,4703/kw/'; break;
                case 'Parts Accessories Bridge Unit / Interchange Unit' :  category_Value = 'c/597,598/kw/'; break;
                case 'Parts Accessories Document Feeder' :  category_Value = 'c/597,599/kw/'; break;
                case 'Parts Accessories Fax Option' :  category_Value = 'c/597,600/kw/'; break;
                case 'Parts Accessories Finisher/Bookmaker' :  category_Value = 'c/597,601/kw/'; break;
                case 'Parts Accessories Gears, Actuators, Brackets, Other' :  category_Value = 'c/597,658/kw/'; break;
                case 'Parts Accessories Memory, Hard Drive, DIMMS' :  category_Value = 'c/597,659/kw/'; break;
                case 'Parts Accessories No Value' :  category_Value = 'c/597,0/kw/'; break;
                case 'Parts Accessories Paper Bank / LCT' :  category_Value = 'c/597,602/kw/'; break;
                case 'Parts Accessories Paper Feed Unit' :  category_Value = 'c/597,1116/kw/'; break;
                case 'Parts Accessories PCBs' :  category_Value = 'c/597,655/kw/'; break;
                case 'Parts Accessories Print / Scan Option' :  category_Value = 'c/597,603/kw/'; break;
                case 'Parts Accessories Sorter' :  category_Value = 'c/597,604/kw/'; break;
                case 'Parts Base Machine Cassettes/Trays/Bypass' :  category_Value = 'c/606,628/kw/'; break;
                case 'Parts Base Machine Covers, Decals, Labels' :  category_Value = 'c/606,619/kw/'; break;
                case 'Parts Base Machine Documentation/Manuals/Software' :  category_Value = 'c/606,617/kw/'; break;
                case 'Parts Base Machine Drum/PCU Section' :  category_Value = 'c/606,611/kw/'; break;
                case 'Parts Base Machine Duplex Section' :  category_Value = 'c/606,612/kw/'; break;
                case 'Parts Base Machine Electrical Components' :  category_Value = 'c/606,615/kw/'; break;
                case 'Parts Base Machine Feed Section' :  category_Value = 'c/606,609/kw/'; break;
                case 'Parts Base Machine Fuser Section' :  category_Value = 'c/606,610/kw/'; break;
                case 'Parts Base Machine Gears, Actuators, Brackets, Other' :  category_Value = 'c/606,657/kw/'; break;
                case 'Parts Base Machine Master Eject' :  category_Value = 'c/606,621/kw/'; break;
                case 'Parts Base Machine Memory, Hard Drive, DIMMS' :  category_Value = 'c/606,656/kw/'; break;
                case 'Parts Base Machine No Value' :  category_Value = 'c/606,0/kw/'; break;
                case 'Parts Base Machine Optics Section' :  category_Value = 'c/606,613/kw/'; break;
                case 'Parts Base Machine PCBs' :  category_Value = 'c/606,607/kw/'; break;
                case 'Parts Base Machine Plotter Unit' :  category_Value = 'c/606,620/kw/'; break;
                case 'Parts Base Machine PM Kit' :  category_Value = 'c/606,618/kw/'; break;
                case 'Parts Base Machine Supplies' :  category_Value = 'c/606,629/kw/'; break;
                case 'Parts Base Machine Toner/Developer Section' :  category_Value = 'c/606,608/kw/'; break;
                case 'Parts Base Machine Transfer/Separation' :  category_Value = 'c/606,616/kw/'; break;
                case 'Printing Solutions AXIS' :  category_Value = 'c/941,851/kw/'; break;
                case 'Printing Solutions No Value' :  category_Value = 'c/941,0/kw/'; break;
                case 'Product Specifications No Value' :  category_Value = 'c/2761,0/kw/'; break;
                case 'Programming External Packages' :  category_Value = 'c/1129,1135/kw/'; break;
                case 'Programming Fax' :  category_Value = 'c/1129,1130/kw/'; break;
                case 'Programming General' :  category_Value = 'c/1129,1139/kw/'; break;
                case 'Programming No Value' :  category_Value = 'c/1129,0/kw/'; break;
                case 'Programming Panel / LCD' :  category_Value = 'c/1129,1133/kw/'; break;
                case 'Programming Print' :  category_Value = 'c/1129,1131/kw/'; break;
                case 'Programming RxOP' :  category_Value = 'c/1129,4234/kw/'; break;
                case 'Programming Scan' :  category_Value = 'c/1129,1132/kw/'; break;
                case 'Recycle No Value' :  category_Value = 'c/2616,0/kw/'; break;
                case 'RFG eSource Content Information' :  category_Value = 'c/622,626/kw/'; break;
                case 'RFG eSource General Info' :  category_Value = 'c/622,623/kw/'; break;
                case 'RFG eSource No Value' :  category_Value = 'c/622,0/kw/'; break;
                case 'RFG eSource Portal' :  category_Value = 'c/622,624/kw/'; break;
                case 'RFG eSource Searching' :  category_Value = 'c/622,625/kw/'; break;
                case 'RFG eSource Subscriptions' :  category_Value = 'c/622,627/kw/'; break;
                case 'RiDP Administration No Value' :  category_Value = 'c/1117,0/kw/'; break;
                case 'RNT TEST - DO NOT USE No Value' :  category_Value = 'c/4382,0/kw/'; break;
                case 'Safety/Environmental Disposal -Fuser Oil' :  category_Value = 'c/950,951/kw/'; break;
                case 'Safety/Environmental Disposal -PCU/AIO/Drum' :  category_Value = 'c/950,953/kw/'; break;
                case 'Safety/Environmental Disposal-Machine' :  category_Value = 'c/950,952/kw/'; break;
                case 'Safety/Environmental Disposal-Toner/Developer' :  category_Value = 'c/950,954/kw/'; break;
                case 'Safety/Environmental Material Safety Data Sheets-MSDS' :  category_Value = 'c/950,636/kw/'; break;
                case 'Safety/Environmental No Value' :  category_Value = 'c/950,0/kw/'; break;
                case 'Safety/Environmental Spill/Clean Up' :  category_Value = 'c/950,990/kw/'; break;
                case 'Safety/Environmental Toner Waste/Recycling' :  category_Value = 'c/950,891/kw/'; break;
                case 'Security Card Authentication Solution' :  category_Value = 'c/2760,4885/kw/'; break;
                case 'Security No Value' :  category_Value = 'c/2760,0/kw/'; break;
                case 'Supplies/Options Batteries' :  category_Value = 'c/589,983/kw/'; break;
                case 'Supplies/Options Fusing Oil' :  category_Value = 'c/589,756/kw/'; break;
                case 'Supplies/Options Fusing Unit' :  category_Value = 'c/589,755/kw/'; break;
                case 'Supplies/Options Ink' :  category_Value = 'c/589,979/kw/'; break;
                case 'Supplies/Options Maintenance Kits' :  category_Value = 'c/589,978/kw/'; break;
                case 'Supplies/Options Markers' :  category_Value = 'c/589,811/kw/'; break;
                case 'Supplies/Options Memory' :  category_Value = 'c/589,802/kw/'; break;
                case 'Supplies/Options NCR Paper' :  category_Value = 'c/589,980/kw/'; break;
                case 'Supplies/Options No Value' :  category_Value = 'c/589,0/kw/'; break;
                case 'Supplies/Options Paper Cassettes' :  category_Value = 'c/589,804/kw/'; break;
                case 'Supplies/Options Paper/Print Media' :  category_Value = 'c/589,5906/kw/'; break;
                case 'Supplies/Options Parts' :  category_Value = 'c/589,879/kw/'; break;
                case 'Supplies/Options PCU/AIO/Drum' :  category_Value = 'c/589,754/kw/'; break;
                case 'Supplies/Options PM Kits' :  category_Value = 'c/589,986/kw/'; break;
                case 'Supplies/Options Staples' :  category_Value = 'c/589,838/kw/'; break;
                case 'Supplies/Options Toner' :  category_Value = 'c/589,757/kw/'; break;
                case 'Supplies/Options Transfer Unit' :  category_Value = 'c/589,895/kw/'; break;
                case 'Supplies/Options Trays' :  category_Value = 'c/589,803/kw/'; break;
                case 'Supplies/Options USB2.0/SD Slot' :  category_Value = 'c/589,4416/kw/'; break;
                case 'testcategory No Value' :  category_Value = 'c/4555,0/kw/'; break;
                case 'Troubleshooting Authentication/Password' :  category_Value = 'c/2575,898/kw/'; break;
                case 'Troubleshooting Device Management' :  category_Value = 'c/2575,4177/kw/'; break;
                case 'Troubleshooting Document Server' :  category_Value = 'c/2575,4196/kw/'; break;
                case 'Troubleshooting Duplicator' :  category_Value = 'c/2575,741/kw/'; break;
                case 'Troubleshooting Electrical' :  category_Value = 'c/2575,700/kw/'; break;
                case 'Troubleshooting Error Messages/LED Light' :  category_Value = 'c/2575,587/kw/'; break;
                case 'Troubleshooting Faxing' :  category_Value = 'c/2575,2579/kw/'; break;
                case 'Troubleshooting Image Quality' :  category_Value = 'c/2575,630/kw/'; break;
                case 'Troubleshooting Jam/Transport' :  category_Value = 'c/2575,635/kw/'; break;
                case 'Troubleshooting Mechanical' :  category_Value = 'c/2575,716/kw/'; break;
                case 'Troubleshooting Networking' :  category_Value = 'c/2575,4195/kw/'; break;
                case 'Troubleshooting No Value' :  category_Value = 'c/2575,0/kw/'; break;
                case 'Troubleshooting Original Transport/Doc Feed' :  category_Value = 'c/2575,637/kw/'; break;
                case 'Troubleshooting Printing' :  category_Value = 'c/2575,705/kw/'; break;
                case 'Troubleshooting Projection' :  category_Value = 'c/2575,6104/kw/'; break;
                case 'Troubleshooting Scanning' :  category_Value = 'c/2575,708/kw/'; break;
                case 'Troubleshooting Service Codes' :  category_Value = 'c/2575,638/kw/'; break;
                case 'Troubleshooting Sorting/Finishing' :  category_Value = 'c/2575,683/kw/'; break;
                case 'Troubleshooting Troubleshooting Assistant' :  category_Value = 'c/2575,5094/kw/'; break;
                case 'Troubleshooting Video Conferencing' :  category_Value = 'c/2575,6103/kw/'; break;
                case 'User Access' :  category_Value = 'c/4691,4695/kw/'; break;
                case 'User No Value' :  category_Value = 'c/4691,0/kw/'; break;
                case 'User Password' :  category_Value = 'c/4691,4696/kw/'; break;
                case 'Service Codes Service Codes'  :  category_Value = 'c/2575,638,638/kw/'; break;
                case 'Service Codes SC100-SC199'  :  category_Value = 'c/2575,638,704/kw/'; break;
                case 'Service Codes SC200-SC299'  :  category_Value = 'c/2575,638,942/kw/'; break;
                case 'Service Codes SC300-SC399'  :  category_Value = 'c/2575,638,943/kw/'; break;
                case 'Service Codes SC400-SC499'  :  category_Value = 'c/2575,638,944/kw/'; break;
                case 'Service Codes SC500-SC599'  :  category_Value = 'c/2575,638,945/kw/'; break;
                case 'Service Codes SC600-SC699'  :  category_Value = 'c/2575,638,946/kw/'; break;
                case 'Service Codes SC700-SC799'  :  category_Value = 'c/2575,638,947/kw/'; break;
                case 'Service Codes SC800-SC899'  :  category_Value = 'c/2575,638,948/kw/'; break;
                case 'Service Codes SC900-SC999'  :  category_Value = 'c/2575,638,949/kw/'; break;
                case 'Service Codes SC1000 and above'  :  category_Value = 'c/2575,638,955/kw/'; break;
                case 'Service Codes SC000-SC099'  :  category_Value = 'c/2575,638,995/kw/'; break;
               default: category_Value = 'kw/';
            }
            var knowledgebaseurl;
            knowledgebaseurl = kb + "/" +  category_Value + sub + "/";
           //alert(category_Value);
           //alert(sub);
           //alert(knowledgebaseurl);
            if (kb == "") {
            knowledgebaseurl   = "https://gestetner.custhelp.com/app/home/";
                          }
            sforce.console.openSubtab(primaryTabId, knowledgebaseurl, true, 
                'KB Search Results', null, openSuccess, 'KBSubtab');
        };

        var openSuccess = function openSuccess(result) {
            //Report whether we succeeded in opening the subtab
            if (result.success == true) {
                //alert('subtab successfully opened');
            } else {
                //alert('subtab cannot be opened');
            }
        };
    </script>
</apex:page>

Any idea and suggestions are appreciated.

Regards,
Raj