Archive Page 2

MCRM 4.0 email router :An error occurred while opening mailbox

In the event log you see the problem while testing the connection .

An error occurred while opening mailbox .


The best way is to play with access credentails and use  enter the user name
and password while configuring the incoming and outgoing access credentails. The user must be able to open the mail boxes in exchange.

please go through from this post .


Reports: An error has occurred during report processing(rsProcessingAborted) CRM 4.0

Error :

An error has occurred during report processing. (rsProcessingAborted)
Cannot create a connection to data source ‘xyz’.
For more information about this error navigate to the report server on the
local server machine, or enable remote errors .
solution :

1 = change the datasource to the “Real” database on the reporting
services . Click properties of a single report and then click on data
source and edit the connection string . after that run it . If it
works then reset the IIS and run the report from CRM interface .
2 =You need to  publish your reports again (PublishReports.exe) . Find the
following exe on the crm server , it should be at (C:\Program Files
\Microsoft CRM\Reports) or search on drive.

CRM 3.0 upgrade issue "There is already an object named ‘AttributeTypes’ in the database "

I am adding the screen shots to make the life easy 🙂

Step1 = enable the full text search enable in organizationName_MSCRM databse

USE Northwind_MSCRM
EXEC sp_fulltext_database ‘enable’

Step2 = Manully add the following columns

Step 3= Make it sure SQL jobs are there and running properly .

Example of CRM 4.0 Plugin

In this example , i will display the number of calls made to an account .Number of calls will display on an account as soon as Sales or marketing people complete the phone calls.
I will make a new read only field on account Form “Total number of calls(new_totalnumberofcalls)” as shown in below figure.

Figure “Call made to an account

Figure = Displaying Total number of calls

Plugin will be registered as ” SetStateDynamicEntity”.

Code :

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.Sdk.Query;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
namespace Microsoft.Crm.Sdk.UpdatingAccount


public class endless : IPlugin

// assigning default value for total number of calls
int NumberOfCalls= 1;
public void Execute(IPluginExecutionContext context)

if (context.PrimaryEntityName == EntityName.phonecall.ToString() && context.InputParameters.Properties.Contains(“EntityMoniker”) && context.InputParameters.Properties.Contains(“State”))


// I will get the current Phone call Id and its state
Guid PhoneCallId = ((Moniker)context.InputParameters.Properties[“EntityMoniker”]).Id;
PhoneCallState stateCode = (PhoneCallState)Enum.Parse(typeof(PhoneCallState), ((string)context.InputParameters.Properties[“State”]));

// Only update the regarding account ‘s field , if the phone call is “completed”
if (stateCode == PhoneCallState.Completed)


ICrmService service = context.CreateCrmService(false);
phonecall myphonecall = (phonecall)service.Retrieve(EntityName.phonecall.ToString(),
PhoneCallId, new AllColumns());
string regardingType = myphonecall.regardingobjectid.type;
Guid regardingId = myphonecall.regardingobjectid.Value;

// Invalid customer type. then return .
if (regardingType != EntityName.account.ToString())

// Retrieve the Account’s traget field

TargetRetrieveAccount target = new TargetRetrieveAccount();
target.EntityId = regardingId;

RetrieveRequest getAccount = new RetrieveRequest(); getAccount.ReturnDynamicEntities = true;

getAccount.Target = target;
getAccount.ColumnSet = new AllColumns();

// Get the account

RetrieveResponse retrieved = (RetrieveResponse)service.Execute(getAccount);
DynamicEntity regardingAccount = (DynamicEntity)retrieved.BusinessEntity;
// If the “Total number of call” exists, update them ,otherwise set it
if (regardingAccount.Properties.Contains(“new_totalnumberofcalls”))
((CrmNumber)regardingAccount.Properties[“new_totalnumberofcalls”]).Value += NumberOfCalls;

regardingAccount.Properties.Add(new CrmNumberProperty(“new_totalnumberofcalls”, new CrmNumber(NumberOfCalls))); }
// Updateing

} }

Example of Custom Workflow Activity (CRM 4.0)

In this example, I will use two dates fields and then calculate the number of days . This can be used for different scenarios. In this example, I will be using scenario like:

When a case is registered, there are different life cycle –Test, In development, In Production.
When technician chooses “In Production” from drop down list, java script populates the “end date” and then the custom workflow assembly will calculate the number of days between both dates.

We have two custom fields on case entity

1 = Case start date
2= Case end date

We would like to calculate the number of days for a given case. I will be using the existing integer(actualserviceunits) field on case form to hold the value .

Result = Case end date –Case start date

I would like to use CustomWorkflowActivity and my input parameters will be :

1 = Guidid of Case (I would like to retrieve the given case and then update it)
2 = Start date
3 = End date

Code :

using System;
using System.IO;
using System.Net;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;

using Microsoft.Crm.Workflow;
using Microsoft.Crm.Workflow.Activities;
using Microsoft.Crm.Sdk.Query;

namespace Updatingincident
[CrmWorkflowActivity(“updating incident”, “cal”)]

public partial class calculate : SequenceActivity
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
IWorkflowContext context = contextService.Context;

ICrmService crmService = context.CreateCrmService();

WhoAmIRequest systemUserRequest = new WhoAmIRequest();
WhoAmIResponse systemUser = (WhoAmIResponse)crmService.Execute(systemUserRequest);

// using the GUID of current case

ColumnSet cols = new ColumnSet();
Guid guidID = new Guid(this.objectID.Value.ToString());

incident ret = (incident)crmService.Retrieve(EntityName.incident.ToString(), guidID, new AllColumns());

DateTime a = DateTime.Parse(;

DateTime b = DateTime.Parse(;

TimeSpan tid = b – a;

CrmNumber tes = new CrmNumber();
tes.Value = tid.Days;
// i will use existing field on CRM incident to hold the integer value.

ret.actualserviceunits = tes;

// updating the case entity

return ActivityExecutionStatus.Closed;

// getting the id of case

public static DependencyProperty objectIDProperty = DependencyProperty.Register(“objectID”, typeof(Lookup), typeof(calculate));

[CrmInput(” objectID”)]
public Lookup objectID
return (Lookup)base.GetValue(objectIDProperty);
base.SetValue(objectIDProperty, value);


// start date as input parameter

public static DependencyProperty startdateProperty = DependencyProperty.Register(“startdate”, typeof(CrmDateTime), typeof(calculate));

[CrmInput(” startdate”)]

public CrmDateTime startdate
return (CrmDateTime)base.GetValue(startdateProperty);
base.SetValue(startdateProperty, value);

// End date as input parameter

public static DependencyProperty enddateProperty = DependencyProperty.Register(“enddate”, typeof(CrmDateTime), typeof(calculate));

[CrmInput(” enddate”)]

public CrmDateTime enddate
return (CrmDateTime)base.GetValue(enddateProperty);
base.SetValue(enddateProperty, value);


Register the assembly

Now we need to register the Custom assembly as pulgin . I would be using plugin developer to register this assembly.

Migrating notes and attachments to the Accounts (Data Migration CRM 4.0)

If we follow the data migration help , the attachment would appear in CRM but without any text (0KB).

I will cover it in the following steps and any input will be appreciated if someone encounter this blog.

1 = First , I have a folder on desktop and under that folder , I have CSV file and another subfolder , where I have documents, I wish to attach with an account. The name of subfolder must be “Documents”.

2 =Map the file to the existing entity and choose “Note” and check the “include attachment”.

3 = During the setup of Data migration, related the “Company Name” on CSV file with regarding and then Choose “Account” and the select “name” (or company , whatever it is in your customize system).

4 = Finally we import the attachments .

Multi-tenancy example in Microsoft CRM 4.0

Hosting companies can have many customers by using single installation of Microsoft Dynamic CRM 4.0 Enterprise.
I used single CRM installation for three organizations named –DK, USA, UK and USA as default organziaton. I used deployement manager to add further organizations -DK and UK.
We have one MSCRM_CONFIG database and three databases for three organizations.

Now one can view the url of all three organizations.