title: Need to direct URL to second tab of tabbed table in xpages
body: <p>Background:  XPage with tabbed table (from container controls) and multiple data sources, one for each tab.   I was having issues with the save button creating duplicates if the users refreshes the page.   To fix this I implemented this solution created by Tommy Valand.  <a href="http://dontpanic82.blogspot.com/2010/06/xpages-avoid-saving-duplicate-documents.html" rel="nofollow">http://dontpanic82.blogspot.com/2010/06/xpages-avoid-saving-duplicate-documents.html</a></p>
  
  <p>The issue is that when the user is on the second tab and saves the document using a full refresh (I have to have this due to attachments).   The function works great except...</p>
  
  <p>The problem:   The redirect always takes the user to the first tab.   This is a problem obviously for every tab except for the first. </p>
  
  <p>I would like to know a way to direct the URL directly to the second tab.   I have tried modifing Tommy's code to include a hash tag, but I haven't been able to get this to work.   I am not even sure that the hash tags work with xpages.   Thanks in advance for help with this issue. </p>
  
  <pre><code> function redirectToCurrentDocument( switchMode:boolean, tab){
    try {
      if( typeof currentDocument === 'undefined' || viewScope.stopRedirect ){ return;       }
      // Gets the name of the XPage. E.g. /Person.xsp
      var page = view.getPageName();
  
      // Finds extra parameters, strips away XPages parameters/trims leading &amp;
      var parameters = context.getUrl().getQueryString().substring(1);
      var extraParameters = parameters.replace( 
       /([&amp;\?^]*_[a-z0-9=]+[&amp;]{0,1})|(action=\w{4}Document[\&amp;]{0,1})|(documentId=[\w]{32}[\&amp;]{0,1})/ig, '').replace( /\&amp;$/, '' );
  
      // Gets the unid of the current document
      //var unid = currentDocument.getDocument().getUniversalID();
      //var unid = document1.getDocument().getUniversalID();  //changed this line to make work with multiple data sources - SJZ
      var unid = document1.getDocument().getNoteID();  //also changed to use NoteID since it gave runtime errors for new documents - SJZ
  
      // Sets/changes the action according according to the mode the document is in
      var isEditable = currentDocument.isEditable();
      if( switchMode ){ isEditable = !isEditable; } // false -&gt; true / true -&gt; false
  
      var action = ( isEditable ) ? 'editDocument' : 'openDocument';
  
      // Open the current document via a get request
      var redirectUrl = page + '?documentId=' + unid + '&amp;action=' + action;
  
      if( extraParameters ){ redirectUrl += '&amp;' + extraParameters; }
  
      print("tab=" + tab)
      if(tab == "Invoices") { redirectUrl += '#tabPanel1'; }
      if(tab == "Credits") { redirectUrl += '#view:_id1:tabPanel2:editPanelCredits'; }
       print(redirectUrl);
      context.redirectToPage( redirectUrl );
    } catch(e){ /* Exception logging */ }
  }
  </code></pre>