Access to Microsoft Dynamics CRM has not yet been fully configured for this user. The user needs at least one security role before you can continue.

I ran into an issue when I was importing a different version  of solution to the organization. The error was:

Access to Microsoft Dynamics CRM has not yet been fully configured for this user. The user needs at least one security role before you can continue.

I was not able to find anything on google/bing for the specific error, but one of the blog I found said the error can be from business rules or other type of processes.

After some research, I came to know that there were multiple Business Rules on the organization which were owned by users who were deactivated and no longer have anything to do with CRM Development.

Resolution:
To resolve this issue, you just  need to assign the Business Processes or other workflows to any active user.

Step 1: Use Advanced Find feature to find the processes and their respective owners.

Advanced Find - Business Rules
Advance Find Business Rules

 

Step 2: Select all results which shows owner who are already disabled.

Advanced Find Result

Advanced Find – Result

Step 3: Assign the Business Rules/Processes to your user account or another user who is in active state.

Assign

Assign processes

And you’re done!! Try to reimport the solution and the error will be gone forever…

CRM 2011: Hitting Save Quote does not do anything, record not saved

Problem:
As described in the subject line, when user hits the Save/Save & Close button, nothing happens. Quote records are not saved, not even a post back happens when hitting save. We checked all different scenarios and nothing worked as Save event was not triggered.

Configuration:
Users/Team were assigned OOB “Sales Person” roles.
Entity: Quote

Resolution:
Give Product entity a full access to the security role and check saving again. It should work.

XrmToolBox – A Must have tool for CRM/XRM Developers

If you are a seasoned CRM/XRM developer, you must have heard about XrmToolbox. If you have, you can simply ignore this post. BUT if you have not then you MUST read on.

This post is about XrmToolbox (http://www.xrmtoolbox.com/) and its plugins which can improve your efficiency and accelerate overall development speed. I intend to list all the default plugins and provide more details on plugins as and when time permits. So here is a list of plugins which gets installed by default.

 

Continue reading on: XrmToolBox – A Must have tool for CRM/XRM Developers

The Microsoft CRM Email Router service on Local Computer started and then stopped

The Microsoft CRM Email Router Service will not start every time you start it manually from Services and throws an error message “The Microsoft CRM Email Router service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service.”

Event log entries say:
Event Type: Error
Event Source: MSCRMEmail
Event Category: None
Event ID: 0
Date:
Time:
User:
Computer:
Description:
#16192 – The E-mail Router service could not run the service main background thread. The E-mail Router service cannot continue and will now shut down. System.Configuration.ConfigurationErrorsException: The E-mail router service cannot access system state file Microsoft.Crm.Tools.EmailAgent.SystemState.xml. The file may be missing or may not be accessible. The E-mail Router service cannot continue and will now shut down. —> System.Xml.XmlException: Root element is missing.

This means your Email Router configuration file is corrupted.

You need to go to C:\Program Files\Microsoft CRM Email\Service and delete the Microsoft.Crm.Tools.EmailAgent.SystemState.xml file. Try to re/start the Email Router Service. This should resolve your problem.

CRM 4.0: Create Dynamic Menu Items

We had a requirements to add Dynamic Menu Items to CRM 4.0 Toolbar. I have followed following blog post by Sonoma Partners for implementing Dynamic Menu Items. I have modified their code with simple JavaScript DOM.

http://blog.sonomapartners.com/2009/12/adding-dynamic-menu-items.html

You can follow above mentioned link to create a stub for the implementation and then refer below mentioned code which uses JavaScript DOM and not JQuery to create them.

function createLinksMenu() {

    var links = getCallLinks();
    var dummyElement;

    var ul = document.getElementById("mnuNew_0_CallCustomer");
    var items = ul.getElementsByTagName("li");
    for (var i = 0; i < items.length; ++i) {
        // do something with items[i], which is a <li> element
        if (items[i].innerHTML.indexOf("Dummy") > 0) {
            dummyElement = items[i].cloneNode(true);
            break;
        }
    }

    // Loop through all the links 
    //   then clone the dummy node, update it as necessary and append it to the menu
    for (var i = 0; i < links.length; i++) {
        //alert(links[i].Name);

        var elem = document.getElementById("mnuNew_0_CallCustomer");
        var newEle = dummyElement.cloneNode(true);
        newEle.id = "CallCustomerMenu" + i;
        newEle.className = "ms-crm-MenuItem-Label";
        newEle.tabIndex = -1;
        newEle.action = "callNumber('" + links[i].Url + "');";
        newEle.innerHTML = "<SPAN class='ms-crm-MenuItem-Label'><A class='ms-crm-MenuLink' tabIndex='-1' onclick='return false;' href='javascript:onclick();' target='_self'><SPAN class='ms-crm-MenuItem-Icon'></SPAN><SPAN class='ms-crm-MenuItem-Text' tabIndex='0'>" + links[i].Name + "</SPAN></A></SPAN>";
        elem.appendChild(newEle);
    }

    // remove dummy node
    items = ul.getElementsByTagName("li");
    for (var i = 0; i < items.length; i++) {
        //alert(items[i].innerHTML.indexOf("Dummy"));

        // do something with items[i], which is a <li> element
        if (items[i].innerHTML.indexOf("Dummy") > 0) {
            items[i].style.display = "none";
            break;
        }
    }
}

CRM 4.0: Import Customization Status check when screen hangs

Ever found yourself in trouble importing customizations in Microsoft Dynamics CRM 4.0? When you want to know what is the progress and the progress bar stops moving further to show the overall process! Try below mentioned sql query to check the progress-

Go to your SQL Server Management Studio and query on the importing Database-

Select * from ImportJob (nolock) order by startedon desc

You will see CompletedOn column either null or filled with Date and Time the importing process completed on. Null says job is not yet completed. You will find many solutions for timeout issues while importing customizations on google.

CRM 2011, C#: Entity Class redefined with .net framwork 3.5 to connect CRM 2011

Look at my previous post on connecting CRM 2011 using .net framework 3.5 without CRM 2011 SDK. https://consultrikin.wordpress.com/2013/09/19/crm-2011-c-connect-crm-2011-without-using-sdkusing-net-framework-3-5/

Here, if you use Entity Class to create Entity records the same way we create records in .net framework 4.0 with SDK in late bound; this requires following syntax.

Entity entity = new Entity();
entity.LogicalName = "contact";
entity.Attributes = new ServiceReference1.AttributeCollection();
entity.Attributes.Add(new KeyValuePair<string, object>("firstname", "test first name"));
entity.Attributes.Add(new KeyValuePair<string, object>("lastname", "test last name"));
OrgService.Create(entity);

Here, you must add an attribute value as a new KeyValuePair<string, object>. Or you need to access the attributes by their indexes like:

Entity entity = new Entity();
entity.LogicalName = "contact";
entity.Attributes = new ServiceReference1.AttributeCollection();
entity.Attributes[0] = "test first name";
entity.Attributes[1] = "test last name";
OrgService.Create(entity);

This code does not have readability as you need to find int index every time you access entity. While I found the same extended Entity Class from the posts I mentioned in my previous post. Here they are listed. Just add them to your project and you will be able to add attributes with string parameters.

/// <summary>
/// Entity Class
/// </summary>
partial class Entity
{
	/// <summary>
	/// Initializes a new instance of the <see cref="Entity" /> class.
	/// </summary>
	public Entity()
	{
		this.FormattedValuesField = new FormattedValueCollection();
		this.RelatedEntitiesField = new RelatedEntityCollection();
	}

	/// <summary>
	/// Gets the attribute value.
	/// </summary>
	/// <typeparam name="T"></typeparam>
	/// <param name="attributeLogicalName">Name of the attribute logical.</param>
	/// <returns></returns>
	public T GetAttributeValue<T>(string attributeLogicalName)
	{
		if (null == this.Attributes)
		{
			this.Attributes = new AttributeCollection();
		};
		object value;
		if (this.Attributes.TryGetValue(attributeLogicalName, out value))
		{
			return (T)value;
		}

		return default(T);
	}

	/// <summary>
	/// Gets or sets the <see cref="System.Object"/> with the specified attribute name.
	/// </summary>
	/// <value>
	/// The <see cref="System.Object"/>.
	/// </value>
	/// <param name="attributeName">Name of the attribute.</param>
	/// <returns></returns>
	public object this[string attributeName]
	{
		get
		{
			if (null == this.Attributes)
			{
				this.Attributes = new AttributeCollection();
			};

			return this.Attributes.GetItem(attributeName);
		}
		set
		{
			if (null == this.Attributes)
			{
				this.Attributes = new AttributeCollection();
			};

			this.Attributes.SetItem(attributeName, value);
		}
	}
}

And Add following Class-

/// <summary>
/// CollectionExtensions Class
/// </summary>
public static class CollectionExtensions
{
	/// <summary>
	/// Gets the item.
	/// </summary>
	/// <typeparam name="TKey">The type of the key.</typeparam>
	/// <typeparam name="TValue">The type of the value.</typeparam>
	/// <param name="collection">The collection.</param>
	/// <param name="key">The key.</param>
	/// <returns>returns TValue</returns>
	/// <exception cref="System.Collections.Generic.KeyNotFoundException">Key =  + key</exception>
	public static TValue GetItem<TKey, TValue>(this IList<KeyValuePair<TKey, TValue>> collection, TKey key)
	{
		TValue value;
		if (TryGetValue(collection, key, out value))
		{
			return value;
		}

		throw new System.Collections.Generic.KeyNotFoundException("Key = " + key);
	}

	/// <summary>
	/// Sets the item.
	/// </summary>
	/// <typeparam name="TKey">The type of the key.</typeparam>
	/// <typeparam name="TValue">The type of the value.</typeparam>
	/// <param name="collection">The collection.</param>
	/// <param name="key">The key.</param>
	/// <param name="value">The value.</param>
	public static void SetItem<TKey, TValue>(this IList<KeyValuePair<TKey, TValue>> collection, TKey key, TValue value)
	{
		int index;

		if (TryGetIndex<TKey, TValue>(collection, key, out index))
		{
			collection.RemoveAt(index);
		}

		//If the value is an array, it needs to be converted into a List. This is due to how Silverlight serializes
		//Arrays and IList<T> objects (they are both serialized with the same namespace). Any collection objects will
		//already add the KnownType for IList<T>, which means that any parameters that are arrays cannot be added
		//as a KnownType (or it will throw an exception).
		Array array = value as Array;
		if (null != array)
		{
			Type listType = typeof(List<>).GetGenericTypeDefinition().MakeGenericType(array.GetType().GetElementType());
			object list = Activator.CreateInstance(listType, array);
			try
			{
				value = (TValue)list;
			}
			catch (InvalidCastException)
			{
				//Don't do the conversion because the types are not compatible
			}
		}

		collection.Add(new KeyValuePair<TKey, TValue>(key, value));
	}

	/// <summary>
	/// Determines whether the specified collection contains key.
	/// </summary>
	/// <typeparam name="TKey">The type of the key.</typeparam>
	/// <typeparam name="TValue">The type of the value.</typeparam>
	/// <param name="collection">The collection.</param>
	/// <param name="key">The key.</param>
	/// <returns>returns true or false</returns>
	public static bool ContainsKey<TKey, TValue>(this IList<KeyValuePair<TKey, TValue>> collection, TKey key)
	{
		int index;
		return TryGetIndex<TKey, TValue>(collection, key, out index);
	}

	/// <summary>
	/// Tries the get value.
	/// </summary>
	/// <typeparam name="TKey">The type of the key.</typeparam>
	/// <typeparam name="TValue">The type of the value.</typeparam>
	/// <param name="collection">The collection.</param>
	/// <param name="key">The key.</param>
	/// <param name="value">The value.</param>
	/// <returns>returns true or false</returns>
	public static bool TryGetValue<TKey, TValue>(this IList<KeyValuePair<TKey, TValue>> collection, TKey key, out TValue value)
	{
		int index;
		if (TryGetIndex<TKey, TValue>(collection, key, out index))
		{
			value = collection[index].Value;
			return true;
		}

		value = default(TValue);
		return false;
	}

	/// <summary>
	/// Tries the index of the get.
	/// </summary>
	/// <typeparam name="TKey">The type of the key.</typeparam>
	/// <typeparam name="TValue">The type of the value.</typeparam>
	/// <param name="collection">The collection.</param>
	/// <param name="key">The key.</param>
	/// <param name="index">The index.</param>
	/// <returns>returns true or false</returns>
	private static bool TryGetIndex<TKey, TValue>(IList<KeyValuePair<TKey, TValue>> collection, TKey key, out int index)
	{
		if (null == collection || null == key)
		{
			index = -1;
			return false;
		}

		index = -1;
		for (int i = 0; i < collection.Count; i++)
		{
			if (key.Equals(collection[i].Key))
			{
				index = i;
				return true;
			}
		}

		return false;
	}
}

Happy Programming!!

CRM 2011, C#: Connect CRM 2011 without using SDK/using .Net Framework 3.5

Recently I had a situation where I was already done with coding with C# 4.0 and CRM 2011 SDK. The issue was the project was built on Visual Studio 2008 with .Net framework 3.5. Now the client did not mention that they do not want to move to .Net framework 4.0. But to use CRM 2011 SDK assemblies I had to convert it to 4.0. I had to convert the project back to .Net framework 3.5.

I searched for solution to this issue and found an interesting posts on MSDN and  this post just follow these steps and connect CRM 2011 with .net framework 3.5:

Steps:

1. Create a .Net project with framework 3.5.

2. Add a web service reference of your organization service – (i.e. http://<server >:<port>/<Organization Name>/XRMServices/2011/Organization.svc?wsdl)

3. You will get all the methods offered by OrganizationService. Check the screenshot.

CRM 2011 Service Reference

CRM 2011 Service Reference

4. Finally Add the following method so that you can get CRM 2011 Service Object.

/// <summary>
/// Gets or sets the org service.
/// </summary>
/// <value>
/// The org service.
/// </value>
public static IOrganizationService OrgService { get; set; }

/// <summary>
/// Gets the CRM service.
/// </summary>
/// <param name="serverHost">The server host.</param>
/// <param name="organizationName">Name of the organization.</param>
/// <param name="userName">Name of the user.</param>
/// <param name="domain">The domain.</param>
/// <param name="password">The password.</param>
public static void GetCRMService(string serverHost, string organizationName, string userName, string domain, string password)
{
    Uri OrgUri = new Uri(string.Format("{0}/{1}/XRMServices/2011/Organization.svc", serverHost, organizationName));

    SymmetricSecurityBindingElement symmetricSecurityBindingElement = new SymmetricSecurityBindingElement();
    symmetricSecurityBindingElement.ProtectionTokenParameters = new SspiSecurityTokenParameters();

    HttpTransportBindingElement httpTransportBindingElement = new HttpTransportBindingElement();
    httpTransportBindingElement.MaxReceivedMessageSize = 1000000000;

    CustomBinding customBinding = new CustomBinding();
    customBinding.Elements.Add(symmetricSecurityBindingElement);

    TextMessageEncodingBindingElement textMessageEncodingBindingElement = new TextMessageEncodingBindingElement(
        MessageVersion.Soap12WSAddressing10, Encoding.UTF8);
    customBinding.Elements.Add(textMessageEncodingBindingElement);
    customBinding.Elements.Add(httpTransportBindingElement);

    EndpointAddress endpointAddress = new EndpointAddress(OrgUri);

    OrganizationServiceClient organizationServiceClient = new OrganizationServiceClient(customBinding, endpointAddress);
    organizationServiceClient.ClientCredentials.Windows.ClientCredential = new NetworkCredential(userName, password, domain);

    OrgService = (IOrganizationService)organizationServiceClient;
}

You now have IOrganizationService instance with all required methods available with CRM 2011 SDK.

Find more about this on my next blog post: https://consultrikin.wordpress.com/2013/09/20/crm-2011-c-entity-class-redefined-with-net-framwork-3-5-to-connect-crm-2011/

CRM 2011, C# Error: The given key was not found in the dictionary.

Many a times unexpected things happen while programming. And in case of Dynamics CRM it “does” happen. Similar issue happened with me today. The subject of the blog post was the annoying error I wanted to get rid off.

The given key was not found in the dictionary.

The first thing comes into the programmers’ mind is that there is nothing in this error and they just need to cross check with the attribute logical names they have used in coding.

To solve this I cross checked each and every attributes from Dynamics CRM and my C# code and not for single but 3-4 times. Finally, I got the idea that all my code is working absolutely correct with nothing wrong in it.

The real issue was not my code but a plugin/workflow activity developed by some other programmer which was registered on the same entity which I was working on. I disabled the step of the workflow activity and the program worked like a charm.

Check for the Plugins or Workflow Activities registered on the same entity to drill down with your issue.

Happy programming!!

Could not load file or assembly ‘microsoft.crm.sdk.proxy’ or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

Hello!!

If you are getting below error when you have deployed your web application which connects to Microsoft Dynamics CRM 2011 online/on premise version.

Could not load file or assembly ‘microsoft.crm.sdk.proxy’ or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

Then probably you have used wrong IIS Application Pool. You might want to change the .Net version of assigned Application Pool to 4.0. And re-run the site.

This should solve the error you were facing.