Note:  This article discusses techniques relevant for Sage CRM v7.1sp2 and earlier.  If you are using Sage CRM 7.2 please refer to the articles that discuss the new Client Side API.
This article has been updated and corrected.

This is a little trick that has to fall into the category "and not a lot of people know that".

Quite a while ago I posted an example of how to carry out a redirect from one screen to another in client side code.
The code used there is:

//This code if placed in Custom Content will redirect page to new location;
var strTargetName = ''
var strPath = document.URL;
var arrayContext = strPath.split('?');
var strContextInfo = arrayContext[1];
document.location.href= strTargetName+'?'+strContextInfo
and is a variant of some code that I have included in the Textpad snippets for the COM API.
//This code if placed in Custom Content will redirect page to new location;
var strFileName = "northwindorders.asp";
var strPath = document.URL;
var arrayApp = strPath.split("eware.dll");
var arrayContext = strPath.split("?");
var strAppPath = arrayApp[0];
var strContextInfo = arrayContext[1];
document.location.href= strAppPath + "custompages/"+strFileName+"?"+strContextInfo+"&J="+strFileName
Both these examples work by grabbing the current document location (document.URL) and redirecting to where you want to go. Part of the job of the code is to get the contextual information that allows a redirect to the new page or external application. This contextual information are the key codes, e.g. key0=1&key1=28&key2=30. In the above code this is context information is held in the variable strContextInfo.

But there is a problem. Normally when entering the screen from a tab hyperlink then the contextual information will look like this

but to enter the same screen from the Recent List, will produce

which of course doesn't contain the key information.
So how can we get the key codes?

Inside every system screen that are some objects and functions created. You are probably aware of the clientside CurrentUser object. But there is also a very useful function called GetKeys().

This can be used to obtain the contextual key codes whether or not the page is called from a tab, a hyperlink, or from the recent list.


This code added to the custom content of the CompanyBoxLong screen will produce the key code like:

This is true whether or not the page is called from the Recent List or from the summary tab of a hyperlink.

The information is then useful for any client side originating request such as a redirect of a javascript call to the webservices API.

As the man is reputed to have said "and not a lot of people know that".

You can download the Textpad snippets from here:
You can find an example of the use of the client side CurrentUser object here: