Another Trick for Grabbing Key Values in Client Side code

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Another Trick for Grabbing Key Values in Client Side code

  • Comments 4
  • Likes
The code in article has been corrected, 7th May 2009.
An individual screen within CRM will be produced as a result of a hyperlink that looks like this:


I wrote a little while ago about the function GetKeys() that is added automatically into the system built screens.

GetKeys will return the keys used to set the context in a handy to use string like this:

But in some circumstances you may not want to get hold of the whole context string but you may want to get hold of an individual variable that has been passed in the querystring. For example you may just want the SID.

The function below allows you to get the value of an individual variables and can be added to the custom content.

function GetKeyValue(querystringname)
var strPath =;
var arrayKeys = strPath.split("&");
for (var i=0;i<arrayKeys.length;i++)
var arrayValue = arrayKeys[i].split("=");
if (arrayValue[0].toLowerCase()== querystringname.toLowerCase())
return arrayValue[1];
return "";

  • Using a regular expression makes it much more concise:

    function QryStr(key){

     var RegExp("([?&]" + key + "=)([^&]*)", "i"));

     return (m)?m[2]:"";




  • That is very nice usage of a regular expression.  I try and avoid using them to make the code as accessible as possible.  I think if I used regular expressions it would make the code too dense and unfriendly to people not used to coding all the time.

  • Hi, is there an easy way to get the CRM instance name from the querystring?

  • In Sage CRM 7.2 you can use


    To return the instance/install name.