title: How come when debugging javascript in CRM 2011 for a form opened up from the ribbon, script blocks are created?
body: <h2>Setup</h2>
  
  <p>I'm adding an appointment to a custom entity in an on site CRM 2011.</p>
  
  <ul>
  <li>I click the "New Activity" button on the Ribbon, select Appointment, then Ok.</li>
  <li>On the new window that opens, I F12 to open the IE debugger, and select the Script tab, set a break point both in my onLoad function, and in the crmForm_window_onload_handler of the FormScript.js.aspx file, and click the start debugging button.</li>
  <li>I then reload the appointment window.</li>
  </ul>
  
  <h2>Issue</h2>
  
  <p>The break point in crmForm_window_onload_handler hits, but when I step into what should be the onLoad function of my custom js web resource file (appointment.js), rather than stepping into the onLoad function of my appointment.js file, it steps into the onLoad of an exact copy of my file, only it's name is script block (some random number from 0-99) ie <code>script block(23)</code>.  Why are these script blocks being created?  In the on Save I'm also running this code:</p>
  
  <pre><code>Xrm.Page.getAttribute('new_issyncreqd').setValue(true);
  Xrm.Page.getAttribute('new_issyncreqd').setSubmitMode("always");
  </code></pre>
  
  <p>But it's not actually saving and I'm guessing it's related to the script blocks... </p>
  
  <hr>
  
  <h2>Update</h2>
  
  <p>I did figure out why the code that is updating the IsSyncReqrdField is not working.  This is for on Site CRM 2011 version V 5.0.9690.1992 (rollup 6).  It apparently has a bug for the Appointment entity where it saves the entity first, then actually runs the custom onSave code.  This is how it currently looks:</p>
  
  <pre><code>function crmForm_onsave_handler(eventObj,eventArgs)
  {
    try
    {
      var eContext=Mscrm.FormUtility.constructExecutionObject(eventObj,0,eventArgs,null);
      eContext = Mscrm.FormUtility.constructExecutionObject(eventObj,0,eventArgs,eContext)
      Mscrm.Form_onsave();
      eContext=Mscrm.FormUtility.constructExecutionObject(eventObj,1,eventArgs,eContext)
      NEW.Appointment.onSave(eContext); // &lt;-- My custom OnSave Handler 
    }
    catch(e)
    {
      displayError('crmForm', 'onsave', e.description);
    }
  }
  </code></pre>
  
  <p>The bug is that the <code>Mscrm.Form_onsave();</code> line is actually saving the record to the database, so when the custom event handler runs, it's already been saved, and any updates made in the custom event handler won't update the record.</p>
  
  <p>The fix for this bug is to set <code>bSaveInProgress = true;</code> in the onLoad of the form, and then 
      bSaveInProgress = !isValid;
      event.returnValue = isValid;
  in the onSave.  The <code>bSaveInProgress = true;</code> will keep <code>Mscrm.Form_onsave();</code> from actually saving the recrod and the event.returnValue will actually cause it to be created.  It works and is a hack, but it's the only thing I've come up with to work around this bug...</p>
  
  <hr>
  
  <h2>The Problem Remains</h2>
  
  <p>Why are script blocks being created and executed instead of using the file that is already there? </p>