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
finalistfinalist 

Returning gracefully to original page when query returns no data

I have an S-Control that is triggered from a button, queries the database for related objects,
and winds up on an edit page for a new custom object in either the Console or a tab depending on where we started.
 
If the query is successful, I call a function, determine by window.parent.location.href whether we're in the Console or not and do what I need to do. 
If the query returns no data, I can display a message to the user (very advanced, I know), but I can't figure out how to get back to where I started.
 
I tried using window.parent.location.href = window.parent.location.href, or using a variable for retURL = "{!$Request.retURL}",
but both of these result in an endless loop of message displays and empty pages.
 
The button's behavior is 'Display in existing window without sidebar or header'
 
Here is my code for determining location, which works fine when there's data:
 
Code:
if(window.parent.location.href=="https://na5.salesforce.com/ui/desktop/DesktopPage")
{
    finishedLocation = '/a0H/e—CF00N70000002Jgyz=' + ... 
       + &CF00N70000002JgwU={!Customer_Subscription__c.Name}
       &CF00N70000002JgwU_lkid={!Customer_Subscription__c.Id}
       &retURL=%2F{!Customer_Subscription__c.Id}&isdtp=mn'
}
   else
{
   finishedLocation = '/a0H/e–CF00N70000002Jgyz=' + ... 
       + &CF00N70000002JgwU={!Customer_Subscription__c.Name}
       &CF00N70000002JgwU_lkid={!Customer_Subscription__c.Id}
       &retURL=%2F{!Customer_Subscription__c.Id}&};
}

 
And here's the code that verifies whether I have any actual results:
 
Code:
if (results.size > 0) {
     var ri = new sforce.QueryResultIterator(results);
       while (ri.hasNext()) {
       // parseServiceBlocks calls the previous ^ function
       parseServiceBlock(ri.next());
       };
} else { 
       // no records were returned, i.e. there are no active Service blocks
       alert("There are no active Subscription & Service blocks for this Subscription");

       // At this point, we want to return the user to the original page 

}

 I'm sure there's a simple way to set window.location to something real, but I haven't figured out what it is.
 
Thanks!
 


Message Edited by finalist on 08-20-2008 03:03 PM
finalistfinalist
When simplicity suffices ...

Code:
function noResultsLocation() {

    try {

          // Determine whether initial location is in the Console

          if(window.parent.location.href==[Console - code omitted, see above]
          {
            finishedLocation = '/{!Customer_Subscription__c.Id}&isdtp=mn'
          }
            else
          {
            finishedLocation = '/{!Customer_Subscription__c.Id}'
          };

     window.location = finishedLocation;

  } catch(ex) {
       displayError(ex);
  }
// end function noResultsLocation
} 

 Thanks for hanging in with me!