Posted on 21. February 2013

Debugging HTML Webresources on localhost

When writing HTML Webresources, I will frequently host the html page on a local development server (e.g. localhost:8777) and make calls to the CRM server on a different port (e.g. localhost:5555). I do this to speed up the debug process since there is no need to deploy the webresource so that it is hosted inside Dynamics CRM. Now that UR12 has introduced cross browser support, the same technique is needed for other browsers.

Since Chrome enforces cross domain checks even for localhost on different ports – I received the following error when trying to call the SDK webservices:

XMLHttpRequest cannot load http://localhost:5555/OrgName/XRMServices/2011/Organization.svc/web. Origin http://localhost:8777 is not allowed by Access-Control-Allow-Origin.

Fortunately, Fiddler has the answer:

1) First Install and run Fidder2 (www.fiddler2.com)

2) Open the 'FiddlerScript' tab and locate the 'OnBeforeResponse' function.

3) Paste the following at the end of the function:

oSession.oResponse.headers.Add("Access-Control-Allow-Origin","http://localhost:8777");
oSession.oResponse.headers.Add("Access-Control-Allow-Credentials","true");
oSession.oResponse.headers.Add("Access-Control-Allow-Headers","origin, soapaction, content-type");
if ((oSession.responseCode == 400) && (oSession.oRequest.headers["Access-Control-Request-Method"]=="POST"))
{
    oSession.responseCode = 200;
}

Note: Makes sure you put your own port number in the Origin parameter.

4) Click 'Save Script'

You requests will now not be blocked by the cross domain policy since Chrome thinks that the server is explicitly allowing the requests to come from a different domain.

@ScottDurow

Posted on 21. February 2013

Corrupt images after installing UR12 OnPrem

I had a strange one today after upgrading one customer's Dynamics CRM servers to UR12.

All was well apart from there being a few places that the images look corrupt.

We tracked the cause down to an image that had not be replaced during the upgrade at the following location:

C:\Program Files\Microsoft Dynamics CRM\CRMWeb\_imgs\imagestrips\grid_ctrl_imgs.png

The pre-UR12 image was:

The new UR12 image should be:

Because this is an image strip, and the images had moved around, the css was pointing to the wrong place – and hence the corrupted images.

Simply replacing the old image with the new one fixed the problem (after a browser cache refresh).

If you have the same problem, you can download the updated image from here:

grid_ctrl_imgs.png (5.46 kb)

Posted on 19. February 2013

App/Command Bar Workbench for Dynamics CRM 2013

The present roadmap for Dynamics CRM has the next version (Dynamics CRM 2013 possibly) sporting the new 'modern' UI throughout. An automatic upgrade path from Dynamics CRM 2011 forms customisations and ribbons will be provided - and it's likely to use a similar RibbonXml like schema under the hood. With this in mind I've done some re-imagining of what the Ribbon Workbench might look like by the end of the year.

Introducing the App Bar Workbench for Dynamics CRM 2013

  •  

    Exciting times are ahead :)

    @ScottDurow

    Posted on 2. February 2013

    Adding Auto Refresh to Dashboards

    This post shows you how to set up a CRM2011 Dashboard 'auto-refresh' feature using the Ribbon Workbench in 10 easy steps (well…11 if you count clicking publish at the end!).

    We will add an auto refresh function to the 'EnableRule' of the Dashboard refresh button that schedules a refresh using the 'setTimeout' function. The EnableRule is called when the dashboard page is first displayed to check if the Refresh Button should be enabled. We schedule the refresh, and then return true to ensure the button is still enabled. This technique can also be used to add JavaScript to areas of CRM 2011 that are not form based.

    Let's get started:

    1) Create a new solution and add the Application Ribbon to it (Client Extensions->Add Existing->Application Ribbon).

    2) Create a new web-resource named 'RefreshRibbon.js' (or something similar)

    Add the following JavaScript to it:

    var AUTO_REFRESH_INTERVAL=30000;
    /// Schedule the first refresh if we havn't already
    function autoRefreshDashboards() {
        var topWindow = window.top;
        if (typeof (topWindow['refreshRegistered']) === 'undefined') {
            window.setTimeout(autoRefreshTimeoutCallback, AUTO_REFRESH_INTERVAL);
            topWindow['refreshRegistered'] = true;
        }
        return true;
    }
    // Refresh the dashboards and schedule the next refresh
    function autoRefreshTimeoutCallback() {
        try {
            Mscrm.DashboardRibbonActions.refreshDashboardPage();
            window.setTimeout(autoRefreshTimeoutCallback, 30000);
        }
        catch ($e1) {
            // Perhaps the dashboards are no longer loaded. and we are on a different page
        }
    }
    
    

    Note: You can change the refresh interval using the 'AUTO_REFRESH_INTERVAL' value which is in milliseconds (30000=30 seconds)

    Your solutions should now look something like:

  • 3) Open the Ribbon workbench, and load up your new solution.

    4) Select the 'Application Ribbon' in the 'Entities' panel if not already, then select the 'Dashboards' tab in the Design surface (be sure to select 'Dashboards' and not 'Dashboard')

    5) Right click on the 'Refresh All' button and click 'Customise Command' (Not Customise Button)

  • 6) Locate the 'Mscrm.DashboardTools.RefreshCommand' command in the 'Commands' section of the 'Solution Elements' panel. Right click, and select 'Edit Enable Rules'

    7) In the Enable Rules dialog click '+Add New' and then select 'Add Step', before selecting 'Custom JavaScript Rule'

    8) In the Enable Rule properties, set:

    FunctionName: 'autoRefreshDashboards'

    Library : Click the lookup button and select the 'RefreshRibbon.js' (If you don't see it, then you forgot to add the javascript webresource you created above to the solution you loaded into the Ribbon Workbench)

    9) Click OK, and OK again.

    10) In the 'Solution Elements' panel, expand the 'Enable Rules' and select 'Mscrm.IsDashboardSelected'. In the properties panel, set 'IsCore' = True.

    This ensures that this rule is not customised in our solution since we only need to customise the Command to add the new enable rule.

    11) Click Publish Solution

    And you're done! This will work both in the Web Browser and the Outlook client. It is important that you remember that auto-refreshing dashboards could place more load on your server if lots of users leave the dashboards open all day!

    Until next time…

    @ScottDurow