Friday, November 25, 2011

Visual Studio 2010 - The version of clr.dll in the target does not match the one mscordacwks.dll was built for

I have prepared new virtual machine for one project (WS 2008, SQL 2008, CRM 2011, VS 2010). I had to develop several plugins and I faced with issue - when I tried to debug plugin and attach to w3wp process I have got following error message - The version of clr.dll in the target does not match the one mscordacwks.dll was built for.

I googled and have found possible solution - Install SP1 for VS 2010. After installation and reboot of virtual machine I was able to attach to w3wp and debug plugins without any issue.

Monday, November 07, 2011

CRM 2011 - reports on data auditing

One of forum visitor asked about building reports based on Audited data. I have never worked with it in CRM 2011 so I decided to recheck how does it store information in DB. Confusing is wrong word for the feelings I've felt... Denormalized data which is impossible to analyse with SQL statements. Anyway following query can help you to build your own reports based on this information:

Monday, August 29, 2011

CRM 4.0 - detach answered email from queue

One of my customers requested following functionality - detach email from queue when email is answered.

Solution consists of 2 parts - customization of email (addition of source email field and JavaScipt which will extract id of source email) and Plugin which will handle Send message.

Sunday, August 28, 2011

Microsoft SQL - How to attach database having only mdf file

Quick trick - I had only mdf file of database without log file. Following t-sql script allowed me to attach mdf file to SQL:

sp_attach_single_file_db @dbname= 'NewDatabase', @physname= 'C:\Directory\DataBase.mdf'

After I ran this script I have got several messages but database was restored and worked fine.

Thursday, August 25, 2011

Sunday, June 12, 2011

How to allow users to input allowed characters in Microsoft Dynamics CRM 4.0

I have already posted here how to restrict user to input special characters to text fields. Following script will allow user to input only predefined symbols to text field.

Saturday, June 11, 2011

Rollup activities for custom entities in Microsoft Dynamics CRM 4.0

Everybody who works with Microsoft Dynamics CRM knows that it is possible to see activities for special entities like contact, account or opportunity but not for custom entities. I had task to develop such kind of functionality. I proposed easier solution - report but customer wanted to have all activities in standard grid.

Friday, June 10, 2011

CRM 4.0 - Error at the stage of creation of the task from plugin

Today I had task to develop plugin which depends on internal logic had to create the task. I used following code inside plugin:

ICrmService crmservice = context.CreateCrmService(false);
task _task = new task();
_task.subject = "Task Subject";

catch(SoapException e)
throw new Exception(e.Detail.InnerText);

When I tested plugin it threw non-descriptive "Generic SQL error". I switched on trace and found following description of an error:

Exception when executing non-query: insert into QueueItemBase(QueueId, OrganizationId, State, Status, ObjectId, ModifiedOn, Priority, CreatedBy, ObjectTypeCode, TimeZoneRuleVersionNumber, EnteredOn, Title, ModifiedBy, QueueItemId, DeletionStateCode, CreatedOn, UTCConversionTimeZoneCode) values ('00000000-0000-0000-0000-000000000000', '7b839df8-96ea-4ee0-85bf-967a5f9060ef', 0, 2, 'a6341e54-5693-e011-aa0e-000c29d64722', '06/10/2011 11:39:51', 1, 'e490fea9-a809-4f08-b79e-392b9355b9f1', 4212, 0, '06/10/2011 11:39:51', 'Subject', 'e490fea9-a809-4f08-b79e-392b9355b9f1', 'a7341e54-5693-e011-aa0e-000c29d64722', 0, '06/10/2011 11:39:51', 0) Exception: System.Data.SqlClient.SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "queue_entries". The conflict occurred in database "orgname_MSCRM", table "dbo.QueueBase", column 'QueueId'.
The statement has been terminated.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.Crm.CrmDbConnection.InternalExecuteNonQuery(IDbCommand command)
at Microsoft.Crm.CrmDbConnection.ExecuteNonQuery(IDbCommand command, Boolean impersonate)
at Microsoft.Crm.BusinessEntities.BusinessProcessObject.ExecuteNonQuery(IDbCommand command, ISqlExecutionContext context)

The issue is when you use code ICrmService crmservice = context.CreateCrmService(false) and you don't fill ownerid field of activity this activity automatically is assigned to 'System' user and 'System' user doesn't has any queues (by default any standard user has 2 personal queues - Assigned and In Progress).

So the way out is to create ICrmService instance using code
ICrmService crmservice = context.CreateCrmService(true);
or fill ownerid field of activities.

Wednesday, January 19, 2011

CRM 4.0 - Assigning Case to Queue

I had the task to assign case (incident) to queue. MSDN has good sample. But this sample didn't solved my problem because in my case not in all situations item was assigned to "In Progress" queue of user. Following code solved my problem.

Sunday, January 02, 2011

MVP Renewed

Second year a row I have got MVP award. I can promise that I will try to do everything to get this award 3-rd time.