Tuesday, July 24, 2012

Working with CRM 2011 Multiple Forms

Multiple forms concept came to CRM with 2011 edition. Previously we only had one form per entity. This was fine, but we needed to use javascript to hide fields based on the security role of the user (if the user was not supposed to see a particular field due to security)

With CRM 2011 we don’t have to use javascripts for this. Of course this is still possible. But there is another way of getting this done. You can use multiple forms.

You can have a form to represent a particular security role and you can have only the fields that particular user role should be seeing. So no more javascripts are needed for this.

However if this is not the reason that you have multiple forms in, but for another reason such as
•    Depending on a particular response the form should be picked
then we need to do some changes.

We had the same scenario and were greatly helped by the following blog posts.


This post describes how to do it.


This blog post has implemented it.

There are pros and cons for each method. The best method to do this cannot be pinpointed as it would depend on the requirement.

In our case we went ahead with

Xrm.Page.ui.formSelector.items.get(itemId).navigate(); (
itemId being the form name or form id)

Wednesday, July 11, 2012

Setting the Default Price List for a Product for the first time

When a product is created for the first time the default price list field is disabled. However you can set a value to this by using a javascript.

var lookup = new Object();
var lookupValue = new Array();
lookup.id = “Guid Value”;
lookup.entityType = “pricelevel”;
lookup.name = “Record Name”;
lookupValue[0] = lookup;

There are very good articles about this which I have given below.



However you might face an issue here as the first time that this fields value is not getting saved to the database. The second time it gets saved.this functionality i have seen only with products. if you save an opportunity you don't get this issue. (If someone has overcome this using javascripts or have done this in any other way than using plugins i would be very much happy to hear about it.)

Is there a way to set the value when the record is saved?.

You cannot use a workflow as the form field is disabled and as you know if a field is disabled on a form then we cannot set a value to it. But using a plugin we can get this done.

We need to use a post create plugin with synchronous mode. I have given below the code for it.
This works correctly and the record is opening with setting a default price list for this field.

        public void Execute(IServiceProvider provider)
            IPluginExecutionContext context = (IPluginExecutionContext)provider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory OrganizationServiceFactory = (IOrganizationServiceFactory)provider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService OrganizationService = OrganizationServiceFactory.CreateOrganizationService(context.UserId);

            switch (context.MessageName.ToLower())
                case "create":
                    Entity target = context.PostEntityImages["Target"] as Entity;
                    EntityReference ent = new EntityReference("pricelevel", new Guid("D63F72CC-41CB-E111-B129-080027B1770C"));
                    target.Attributes.Add("pricelevelid", ent);

Adding a web resource as an image to site map

Is this necessary? This might seem not necessary if you have access to all the images that have been added and you do have them. But there are occasions when you don’t have the images or you haven’t kept the images in a repository and you wonder what to do now.

This problem can be solved by adding the relevant sitemap images (at least the navigational) as web resources and setting the image url to the web resource.

I have shown how this can be done below.

For this to work out you need to add the image as a web resource and should give the name pwks_Mngt to it. You can give any name you want. Then the image is distributed with the solution and you will not have any issues finding the image file.

Sunday, July 8, 2012

Managed VS Unmanaged Solutions

This is a debate that most of the developers of CRM 2011 have. Whether to us a managed solution or an unmanaged solution in UAT and Production environments?

Some prefer to use managed solution as this way the customer will not be able to change the solution attributes that the developers have added. Some don’t think like that as they tender to think about the advantageous that using an unmanaged solution would give.

I would prefer having an unmanaged solution in the development and managed solutions in the UAT and Production environments as it would keep the control in our hands. However there are pros and cons to this as well.

There is a great article that has been written by Gonzalo Ruiz regarding this topic of managed and unmanaged solutions at the following link.


Also he has written another nice article about deleting an attribute from a managed environment in the following article.


Both these articles are great articles to read if you are person working with CRM. This would give you some insight of how the things are happening and how you can cope up with them.

Wednesday, July 4, 2012

Change the default browser in VS 2010

When working with web applications and when you debug a web page normally you start with an IE with the page details. Sometimes you might want the browser to be firefox, chrome or safari or the other way around.

This is pretty easy to do. All you have to do is to go to your web page. Right click on that and select browse with and you will be able to choose the browser of your liking.


You can set the default browser here as well by selecting a browser and clicking on set as default button.

Scott Guthrie has written a nice article regarding this.


Tuesday, July 3, 2012

CRM 2011 How to increase the upload size

With CRM 4 when we want to increase the upload size we went to the web configuration file and
changed the maxRequestLength property to the size that we wanted to.

However with CRM 2011 you don’t need to update the web configuration file, but update a field in
the config database.

By running the below statement you can find out the upload size of the documents.

select IntColumn from ServerSettingsProperties where columnname=’ImportMaxAllowedFileSizeInMB’

You can change this by running the following statement in SQL Server.

Update ServerSettingsProperties set IntColumn = 100
where columnname=’ImportMaxAllowedFileSizeInMB’

This will increase the upload amount to 100 MB. Please note after doing this you will have to do an iisreset for the upload size to take the size of the changed value.

We were helped by the following article when we had the same problem.

Monday, July 2, 2012

Disabling View Picker in a Look up (disableViewPicker )

There are times that we want the lookup filter to be disabled and display only the view that we want the customer to see. This is possible by creating a custom view and using the in-built functionality of CRM look up filter to the view picker.

If you want to do this in java script how would you go on about it? Is there a way?

There are couple of java scripts that you can write. However some of them won’t work with some of the Update roll ups in CRM 2011. Here I have listed some of them below.

Xrm.Page.ui.controls.get("lookupname").$0_3._element.disableViewPicker = 1;
This works with UR 6, but doesn’t work with UR 8.

document.getElementById("lookupname").disableViewPicker = 1;
The above seems to be a safe bet as it works with UR 6 and 8 both.

Retrieving Calendar of a Bookable Resource in Dynamics

There are occasions where we need to retrieve working days and working times of a resource in Dynamics grammatically. This is quite possible...