Custom ASP page redirect loses company context

I've created a custom table linked to a company and applied the logic described here : https://community.sagecrm.com/partner_community/b/hints_tips_and_tricks/archive/2010/06/08/how-to-create-a-secondary-entity-for-a-new-custom-primary-entity.aspx#pi10465=2

to get a simple edit screen to add new entries. For the most part this all works well, but I've run into a persistent issue with the redirects upon saving on the Edit page and the Add page.

I used

Response.Redirect(CRM.URL("company/companypreferenceslist.asp")+"&T=company&comp_companyid="+intRecordId);

but the resulting url changes the context to teams for some reason. If I then manually change the url key0=5 back to key0=1 as it was up until the save button was clicked, I get the proper header and tabs. I just can't figure out why this changes to key0=5 in the first place.

This is happening in CRM 2017 R2.

Any ideas of what I can do to preserve the company context here?

  • 0

    Kevin

    The method CRM.URL() will build the URL with the context information.

    Look at the URL that is built using just

    CRM.URL("company/companypreferenceslist.asp")

    What is the value of Key0?

    Note: You can always construct the path yourself

    There is a lot of information available to the standard ASP pages e.g.

    Request.ServerVariables("SERVER_NAME"),

    And the name of the CRM install can be found very easily using a function contained in the standard include file (sagecrmnolang.js)

    getInstallName(Request.ServerVariables("URL"));

  • 0

    Kevin

    I was expecting the CRM.URL("company/companypreferenceslist.asp") to set the context to Key0=5. This is probably based on the existing context in which the page is called. You can force a next context by changing the values of Key0 and the other context keys.

    In this case I think you may find it best to build the whole of the URL yourself.

  • 0

    Using only CRM.URL("company/companypreferenceslist.asp") still changes to Key0=5, while this new table doesn't contain a link to teams at all.

    I suppose building the URL manually will be the most reliable solution as it stands.

  • 0

    The existing context had Key0=1, as this asp page is being called from a Company tab. That's why it is so confusing that the CRM.URL command is changing this to teams. The resulting page works, but the heading/top content is showing a team list instead of the company context as it should (this also makes the other tabs disappear)