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:

 
 
 
<script>
//This code if placed in Custom Content will redirect page to new location;
var strTargetName = 'http://www.sage.com'
var strPath = document.URL;
var arrayContext = strPath.split('?');
var strContextInfo = arrayContext[1];
document.location.href= strTargetName+'?'+strContextInfo
</script>
and is a variant of some code that I have included in the Textpad snippets for the COM API.
<SCRIPT>
//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
</SCRIPT>
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

&Act=220&CLk=T&Key0=2&Key2=37&SID=200935213023582
but to enter the same screen from the Recent List, will produce

SID=200935213023582&Act=520&Mode=1&CLk=T&RecentValue=220x2x37
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.

<script>
document.write(GetKeys())
</script>

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

&Key0=1&Key1=28&Key2=30&Key4=1
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: