Thursday, January 12, 2012

Developing CRM Silverlight Web Resources outside of CRM

 

When you are developing a Siverlight web resource for use in Microsoft CRM it can be a pain having to deploy the XAP web resource each time you want to do some testing.

The microsoft recommendation is to ‘Write and test as much of the application as you can without requiring contextual data from Microsoft Dynamics CRM.’

Then when you want to start writing the bits of the app that require context information you have to redeploy you resource each time.

A way round this problem is to mock the Xrm.Page.context property that is available when your app is hosted in CRM – this lets you take your application further before you have to deploy.

In the aspx page you are using to test the silverlight app add a snippet similar to the following the following code snippet to hard code some context values:

    <asp:ScriptManager ID="ScriptManager1" runat="server">

    </asp:ScriptManager>

    <script type="text/javascript">

        Type.registerNamespace("Xrm");

        Xrm.Page = function () { };

        Xrm.Page.registerClass("Xrm.Page");

        Xrm.Page.context =

        {

            getUserId: function () { return "e2511a4a-f914-e111-91ba-00155d828444" },

            getServerUrl: function () { return "http://crmserverurl" }

            //See http://msdn.microsoft.com/en-us/library/gg328399.aspx for a list of

            //available functions

        };

    </script>

 

Note ScriptManager is part of the Microsoft AJAX Extensions library

No comments:

Post a Comment