Changing Context when jumping between pages using the COM ASP API

1 minute read time.
 I have created a very simple page that contains a couple of buttons. The starting page is an ASP page in the context of the Opportunity. These buttons will allow me to jump to different places in the application. The first "company" button jump is built using

var strCompanyButton = CRM.Button("Company","findcompany.gif", CRM.Url(200));
myBlock.AddButton(strCompanyButton);

The button when pressed will call the internal CRM action 200. This is the companysummary action and it will automatically change contexts and ensure that the correct information is displayed in the top content area.

If I wanted to call an ASP page I can do this from a button using

var strCustomButton = CRM.Button("CustomJump","myimage.gif", CRM.Url("custompage.asp"));
myBlock.AddButton(strCustomButton);

But this assumes the jump is taking place within the same context. The topcontent detailing the opportunity would not change and, unless I explicitly called the correct tab group in the destination page, the opportunity tabgroup would still be used.

This is because context is determined by the name/value pairs in the querystring that is passed to the eWare.dll. The CRM.URL() method when used on an ASP page builds the URL needed to maintain session but keeps the current context.
Below is the result of my custom Person jump and we can see here the topcontent and menus are all correct and even the "Testjump" tab has been correctly highlighted.


I made sure that this was the case by controlling the context myself.

The code behind the button looks like:

var strSID = new String(Request.QueryString("SID"));
var intDominateKey = 2; //person is the new target context
var intKey1 = 28; //unique id of target company
var intKey2 = 30; //unique id of target person
var strFileName = "testjump.asp"; //target file
var strTabName = "Person"; //tabgroup name to be used.
var strTarget = "http://localhost/CRMdemo/CustomPages/testjump.asp?SID="+strSID+" &Key0="+intDominateKey+" &Key1="+intKey1+" &Key2="+intKey2+" &J="+strFileName+" &T="+strTabName;

var strPersonButton = CRM.Button("Person","findperson.gif",strTarget);
myBlock.AddButton(strPersonButton);

I hardcoded some of the values above. In the real world the values would be derived from the existing context. Hopefully the comments make it clear what needs to be changed. The most important part is the change in the dominate key (Key0).

Other useful articles:

Key Values in URLs

Parents
  • I think we need to look at the URLs and how they are being formed.

    The SQL Tab Clauses use the either the context of the user (basically the SID variable in the URL determines this) or it is determined by the entity in context. This is determined by the value of the dominant key.

    The SQL log should contain a hint as to how the SQL related to the tabs is being malformed. This is if it thinks it is addressing the wrong entity or is not finding the key value.

    But a side by side comparison of a 'working URL' that allows the page to be displayed with the working SQL Tab Clauses and one that is generated by the ASP page and contains the errors should allow you to identify how the error-generating URL should be changed.

Comment
  • I think we need to look at the URLs and how they are being formed.

    The SQL Tab Clauses use the either the context of the user (basically the SID variable in the URL determines this) or it is determined by the entity in context. This is determined by the value of the dominant key.

    The SQL log should contain a hint as to how the SQL related to the tabs is being malformed. This is if it thinks it is addressing the wrong entity or is not finding the key value.

    But a side by side comparison of a 'working URL' that allows the page to be displayed with the working SQL Tab Clauses and one that is generated by the ASP page and contains the errors should allow you to identify how the error-generating URL should be changed.

Children
No Data