Lost Context Response.redirect

Help!

Hoping someone can assist me with an ASP page. I have the page the way that I need it. However, I lose context with the company record I am on after saving the page. After saving, I need to have one field populated and then I want to return to my asp page in view mode. My page is called CHSleasecf.asp

Here is the page code...any assistance would be greatly appreciated!!

//Get Container Block

var Container=CRM.GetBlock("Container")

//Define Context

var ThisCompanyId = CRM.GetContextInfo('Company','Comp_companyId');

//Find record from custom entity (CHSleasecf) and tie it to the context (Company)

var ThisCompanyRecord =CRM.FindRecord('CHSleasecf','lcf_companyid='+ThisCompanyId);

//Define the data block

companyblock=CRM.GetBlock("CHSLeaseCFDetailBox");

//Define the where clause

companyblock.ArgObj=ThisCompanyRecord;

//Add the block to the container

Container.AddBlock(companyblock)

//Actions if page is in Edit mode

if(CRM.Mode == Edit)

{

//Add Canel button to edit page

Container.AddButton(CRM.Button("Cancel","Cancel.gif",CRM.URL("CHS/CHSleasecf.asp")));

}

//Generate HTML

//Add the container block to the screen

CRM.AddContent(Container.Execute());

//Deliver the page to the web

Response.Write(CRM.GetPage())

//Actions if page is in Save mode

if(CRM.Mode == Save)

{

ThisCompanyRecord.lcf_UpdateTL='Y'

ThisCompanyRecord.SaveChanges();

Response.Redirect(CRM.URL("CHS/CHSleasecf.asp"));

}

Thanks!

  • 0

    Hi Michelle,

    Fun and more fun! Is this any help to you? SetContext may be what is missing. community.sagecrm.com/.../addcontent-and-getpage-versus-gettabs-and-execute-in-com-asp-api.aspx

    Regards,

    Penny

  • 0

    You could also try changing the redirect to:

    Response.Redirect(CRM.URL("CHS/CHSleasecf.asp" + "&Key1="+ThisCompanyId));

    It would be useful to see the URL of the page once it has lost context to see what other Keys may be missing.

  • 0

    Penny...

    Thank you for the suggestion. I was not able to pull a solution out of the post. However, the article did help me better understand the various mechanisms to use when rendering a page. Therefore, I thank you very much. I will do some additional studying in case I missed something.

  • 0

    Daniel...

    Thank you for the reply...I see what you are doing and it makes sense. I tried adding the above code to my page and it throws a 404 page error.

    The URL I end up with after I loose context is as follows...

    sagecrm/.../CHSleasecf.asp

    Based on the page code that I originally had, I don't understand how the Person Key (2) and the Channel Key (5) are ending up in this URL. I am ending up in the Team pages...this is what my screen looks like...

    Any additional assistance that you can provide would be greatly appreciated

  • 0

    I think I got this figured out. It appears I was making this too hard (yes..I am blushing) . After the save, I want to return to the page I was editing.

    I thought I needed a response.redirect in my "if" function for the Save. However, I started thinking this is not necessary when you are on a page in view mode and then edit it. When you save, it just goes back to the page you were editing in view mode. Therefore, I removed the response.redirect from the Save. When I did that, it worked. I guess I thought because I asked it to do something when I hit the save button, I would also need to tell it where to go back to. It appears I do not. (Again...I am blushing.)

    I greatly appreciate your responses because I did learn additional options to think about when something is not working correctly! :-)