Bhoopathi

"Be Somebody Nobody Thought You could Be"

Thursday, February 16

Improving Performance of CRM Forms with IFrames

Posted by Aiden Kaskela on Jan 16, 2015 3:02:43 PM

Microsoft Dynamics CRM has long supported Iframes on forms but the way they’re implemented usually has a negative impact on form load times. While I was researching the form load process in CRM, I came across a great topic on MSDN which describes how Iframes should be loaded for best performance. The article at ‘Write code for Microsoft Dynamics CRM forms’ (http://msdn.microsoft.com/en-us/library/gg328261.aspx) suggests using collapsed tabs to defer loading web resources, which means we can eliminate the load times for Iframes completely if you’re not going to use it. The idea is, instead of setting the Iframe URL in OnLoad you use the TabStateChange event, which fires when the Tab is expanded and collapsed.
To implement this we need to add a Javascript web resource for setting the URL, the form customizations with the tab and Iframe, and update the tab event to call the Javascript. In this scenario we’re going to set up an Iframe to show an Account’s website.

Setting up the Web Resource

Go to your default (or named) solution and add a new Web Resource of type Script (Jscript). The name of my script is cobalt_DeferredFormLoad. After saving the resource, click on the Text Editor button to enter your script.
frame1
This is the script I’m using to set the URL. It’s quasi-generic, and will work for any entity where there is a website field on the form. The function takes in the name of the tab, the frame, and the attribute of the website.
function LoadIFrame(tabName, iframeName, websiteAttribute) {
    if (tabName != null && iframeName != null && websiteAttribute!= null ) {
        var isTabExpanded = (Xrm.Page.ui.tabs.get(tabName).getDisplayState() == "expanded");
        var websiteUrl = Xrm.Page.getAttribute("websiteurl").getValue();
        if (isTabExpanded == true && websiteUrl) {
            var IFrame = Xrm.Page.ui.controls.get(iframeName);
            if (IFrame != null) {
                IFrame.setSrc(websiteUrl);
            }
        }
    }
}

Adding the Form Customizations

From the Account form, insert a new Tab and leave the default values. Click in the Section area of the new tab and insert a new Iframe from the Ribbon Bar. Give the frame an appropriate name (IFRAME_CompanyWebsite) and any default URL. I unchecked ‘Display label on the Form’ because the tab label looks good on its own.
frame2
Now that the Iframe is setup you need to configure the Tab properties to load the Iframe. Under the Display tab, give an appropriate name and label, and uncheck ‘Expand this tab by default’.
frame3

Configuring the Event

With the Tab properties open, go to the Events tab, Add your new web resource, then Add a new Event Handler
frame4
In the Event Handler screen, fill in the name of the Function from the Javascript (LoadIFrame), and in the parameters section, list the parameters that need to be passed in the to function. The parameters are the name of the Tab, the name of the Iframe, and the name of the field that contains the URL to set. Remember that you’re specifying a string value and each parameter should be enclosed with a single quote mark.
frame5
Once you save and publish the customizations you can verify the results on your entity. Open the account form and find your new Tab, expand it, and verify everything opens correctly.

Wednesday, February 15

Calling a Workflow from Ribbon Button - MS CRM

Friday, February 3

How to copy Microsoft CRM 2011 organization on the same server


There are many reasons to copy organizations, one of the most common - for testing purpose.
You can do as following:
1. Select a database in SQL Server Management Studio which will be copied (TEST_MSCRM). Right click on the target database -> Tasks -> Backup.



2. Select Full for Backup type and press OK.

3. Right Click on Databases -> Restore Database.

4. Put the name of new database (TEST2_MSCRM) and select file from local disc a copy of TEST_MSCRM.bak.

5. Open CRM Deployment Manager -> Import Organization Wizard.
6. Select SQL server and database (TEST2_MSCRM) and Next.

7. Enter a Display name TEST2 and press Next.

8. Enter Report Server URL and press Next.

9. Select Automatically Map Users as recommended and press Next.

8. Press Import.
9. Press Finish.

10. Congratulations. New organization is created.
11. Go to Internet Explorer and enter address http://your_server _name/TEST2 and you will see a new fresh copy of your organization.