CreateScript to update a field value before load

SUGGESTED

I've written a CreateScript that interrogates a value in a date field on the page to see if it is less than the current system date. If it is, the value of another field from the same page is updated in the database. This is working fine but I want to force a Refresh / Reload of the current page so the update that has just been performed is visible to the user. If I manually hit F5 in the browser the change is displayed. So I'm looking to programmatically mimic the behaviour of the F5 button.

Parents
  • 0

    You're going to need to post the script.

  • 0 in reply to Vega

    var expDate = new Date(Values("comp_suppexpdate"));
    var sysDate = new Date();

    if (expDate < sysDate)
    {
    Values("comp_supporttype") = 'lapsed';
    var intRecordId = CRM.GetContextInfo("Company","Comp_CompanyId");
    var recComp = CRM.FindRecord("Company",'Comp_CompanyId='+intRecordId);
    recComp.comp_supporttype = 'lapsed';
    recComp.SaveChanges();
    }

  • 0 in reply to NWSageCity

    The Values collection is only for data that is submitted from the screen. If you need to reload, then (assuming this is a company summary screen) you could try after the SaveChanges() a call to CRM.Url(200); This might work as it will execute the action code 200 which is the company summary screen, which in effect will reload it.

  • 0 in reply to Vega
    SUGGESTED

    Actually, that won't do what I thought... Calling CRM.Url(200) will return a string to call the action code for a company summary. If you need to redirect, you will need to create a stub ASP page that contains the standard includes for a CRM ASP page, and then have a Response.Redirect(CRM.Url(200)); in it as its only line of code in the body. This is because you can't (as far as I recall) do a redirect from within the server side scripts. You can from external ASP scripts though.

Reply
  • 0 in reply to Vega
    SUGGESTED

    Actually, that won't do what I thought... Calling CRM.Url(200) will return a string to call the action code for a company summary. If you need to redirect, you will need to create a stub ASP page that contains the standard includes for a CRM ASP page, and then have a Response.Redirect(CRM.Url(200)); in it as its only line of code in the body. This is because you can't (as far as I recall) do a redirect from within the server side scripts. You can from external ASP scripts though.

Children