Project Description
Creates a knockout model of a Dynamics CRM form that can be used in a Web Resource

Installation
  • Upload the kocrm.js file into your Dynamics CRM Solution (See downloads)
  • Upload the latest version of knockout.js (tested up to version 2.2.0) into your Dynamics CRM Solution
  • On the dynamics CRM form include both knockout, and kocrm (in that order)
  • On the page load add the following event:

kocrm.bindToCrmModel

Web Resource
  • In a webresource where you want to you use the model, add the following script:

function doBinding(ko, model)
{
    // ko is a knockout reference from the parent form
    //  document.body is important here because we need to bind in this frame
    //  use model, or any variation of a view model derived from model to bind.
    ko.applyBindings(model, document.body);
}
  • Any field that is on the form, or (hidden) on the form can be used in the web resource, by its attribute name

<input type="text" data-bind="text: new_name" />
  • Writing back and forth from either field will cause the model to notify and the UI to rebind

Last edited Apr 29, 2013 at 12:40 PM by methodworx, version 8