Tuesday, December 18, 2012

CRM 2011 Plugin Images – Target Image

As we all know when a record creation is happening we can find the information of the attributes in that event using Target image from the Pre create event.

You get all the values in the Target image from the Create event.

You get the same image in the update as well. But there is a different.

In update you only get the changed attributes. Not all the attributes of the record. So if you want to get all the attributes of the record you need to do some alternatives.

The best would be to merge the Pre image of the event with the target image.
However please do keep in mind when you are doing that you need to give precedence to the target image and add any attribute that is not in the Target image from the Pre image. If not you will be misguided and will not be able to produce the correct result that you are planning to have.

Thursday, September 6, 2012

Error message “User does not have send-as privilege.” when sending emails programmatically in CRM 2011

We were working on sending emails programmatically using CRM and all were working fine. Suddenly we got this error when we tried to send an email. It was strange to us as this functionality was working fine before. So we did some digging to find out what had changed to cause this issue. We found out that one of us had changed the email sending user from the admin user to another user.

We use a CRM user to work with a web portal and we have used the same user as the email sending user. Hence we didn’t get any errors as the same user can send emails to anyone using the same user account. (no impersonation is here).

But when you try to send an email from someone else using a different user account you get and error as the email sending user has not granted permission for others to send emails on behalf of him. You can grant the permission by going to personal user setting of the email sending user and selecting “Allow other Microsoft dynamics CRM users to send email on your behalf”.

After doing this our problem was solved and we were able to send emails.

You can refer the following articles for more details



Monday, August 13, 2012

Dependent Optionlist/Picklist values in CRM 2011

This is not possible with OOTB CRM features. We can use lookup options with cascading features from OOTB functions.

So is there a way to come around this? Yes, there is. There is a solution which has been created and shared among the developers. This is perfect when it comes to CRM interfaces.

The links below would take you to articles which describe it more.

The recurring problems have been included in this article.

Please not you can have multiple picklist dependent on the same picklist in an entity. This is supported. All you have to do is to create a single web resource with all the mapping data inside it and it will work. 

If you have any issues doing the above let me know.

Thursday, August 9, 2012

CRM 2011 Integer fields and comma symbol

In CRM if you create an integer field by default the CRM group 2 numbers together by using a comma. This is the standard feature.

However sometimes customers ask this comma to be removed. This is not possible with OOTB functionality in CRM. You have couple of options.

•    Remove the integer field, have a text field and include javascripting to validate the field. This might be cumbersome.
•    Can create another field (text) and using a workflow assign the value of the integer field to this. This field would be getting displayed in views and forms. The drawback is you have synch both these fields.
•    You can have a javascript to remove the comma from the CRM form when it’s loading. Not much difficult. However you still would not be able to get rid of commas when you display a view.

Below I have given a common javascript function which can be used to get rid of commas. Add this to a web resource.

function RemoveComma(fieldname)
document.getElementById(fieldname).value = Xrm.Page.data.entity.attributes.get(fieldname).getValue();

•    Add the web resource to form onload event.
•    Call the function RemoveComma with the field name as the parameter.

This way you can use this function anywhere you want just by passing the field name to it.

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.

Thursday, June 28, 2012

Multi Selection option Lists in CRM 2011

Sometimes customers ask showing an option list whether it’s possible to have a multi selection list instead of an option list which will let the customer select only one option from the list. Unfortunately this is not supported with CRM 2011.

However there are ways to get this done and the following blog post state a very nice way to get this done. Please note as the author of the post says it’s unsupported.

Cross Brower compatibility with CRM 2011

When speaking about CRM one of the major limitation we had was it was only supported in IE. So most of the users were not too thrilled of the fact that CRM not supporting their favorite Browser (Not all... IE is favorite for most of the cases). But the fact remained that CRM not supporting anything other than IE.

Microsoft has been working regarding this for some time and they have made it to work with chrome and Mozilla. For chrome and Mozilla you have to work with the latest version of them. This is coming with UR 9 of CRM 2011.

However there is a catch. The javascripts that we have been using, some of them will get obsolete as they were targeting IE only. Since with this roll up, we will have to re write them to be compatible with other browsers. Might be a tedious task. But once this is done you will be able to work with almost 3 browsers and like any other traditional .net web app, you will have to check with cross browsers to see the system is working.
More information about this can be found at the following link.

Tuesday, June 26, 2012

Making an EntityReference in a CRM 2011 to Null Programmatically

First of all, is this needed? Yes, we need to do this when working with c# code sometimes where we want to clear a look up field value. 

How can we do this?

It’s very easy. All we have to do is assign null value to the field. That would do the trick.
contact.parentcustomerid = null;

the above statement will clear out the parent customer value in a contact.

Thursday, June 21, 2012

Window.event.target javascript in IE 8

We needed to get the id of an event that fired and we used event.taget.id there. We tested this functionality in IE 9 and Mozilla Firefox and it was working fine. 

However when this was tested with IE 8 it was not working and it gave an error saying that the target.id is null. Strange ha…

So we did some research on this with the help of google and found out that this is not working with IE 8. In IE 8 if you want to get the Id you need to use the srcElement attribute.
So instead of event.taget.id it should be event. srcElement.id in IE 8.

The best way to get this is use the following method. 

var controlId = (event.target || event.srcElement).id

This would give you the id of the event of the attribute that fired.

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...