Category: Microsoft Dynamics CRM

HTML Web Resource in CRM

In Microsoft Dynamics CRM HTML web resource we have Xrm.Page.context parameter from where you can get different information about your CRM/Page etc…

image

This gives an impression that we will have access to all other XRM scripting properties like Xrm.Page.data etc… but that is not the case.

I was having requirement to get the record ID and found given msdn document. Which tells you can pass the records as parameters.

http://msdn.microsoft.com/en-in/library/gg309536.aspx#BKMK_PassingParametersToWebResources

How to Do It:

Go to Web resource Properties in form Editor, Select given check box.

image

You will be able to get the record id in URL.

Pre Check Box Checked

image

Post Check Box Checked (there is a whole lot of stuff as given in msdn)

image

Fetching Data from Query String GetQueryString(“id”) will give you the record id. Similarly you can fetch other values as well.

[code language=”javascript”]
function GetQueryString(key) {
var resourceUrl = document.location.href;
var queryList = resourceUrl.split(/[?&]+/);
for (i = 0; i < queryList.length; i++) {
pair = queryList[i].split("=");
if (pair[0] == key) {
return pair[1];
}
}
}
[/code]

Record in Multiple Queue Error in CRM 2011

While looking at Queue Item Details we were getting Error

Error:

“This record is in multiple queues. Go to specific queue to view details.”

Cause:

On doing the repro steps it was realized that this is the message that we get when a case is reactivated after being closed.

This is because a queue item related to same case is already there in CRM in deactivated state.

Resolution:

To resolve this we wrote a plugin to reactivate the queue item and assign it to a next level queue based on business logic.

Source Code to Reactivate Queue Item (Entity) in CRM 2011

[sourcecode language=”csharp”]

var entityMoniker = localContext.PluginExecutionContext.InputParameters[“EntityMoniker”] as EntityReference;

var incidentid = entityMoniker.Id;

QueryExpression query = new QueryExpression();

query.EntityName = “queueitem”;

query.ColumnSet = new ColumnSet();

query.ColumnSet.Columns.AddRange(new string[] { “statecode”, “statuscode”, “queueitemid” });

query.Criteria = new FilterExpression();

query.Criteria.AddCondition(“objectid”, ConditionOperator.Equal, incidentId);

query.Criteria.AddCondition(“statecode”, ConditionOperator.Equal, 1);

EntityCollection results = serviceContext.RetrieveMultiple(query);

if (results != null && results.Entities != null && results.Entities.Count > 0)

{

SetStateRequest setQueueItemState = new SetStateRequest();

setQueueItemState.EntityMoniker = new EntityReference(“queueitem”, results.Entities[0].Id);

setQueueItemState.State = new OptionSetValue(0);

setQueueItemState.Status = new OptionSetValue(1);

serviceContext.Execute(setQueueItemState);

}

[/sourcecode]

Repro Screenshots:

  1. Create case:

 

  1. Add it to queue


     

  2. Work On


     

  3. Resolve it


  4. Reactivate it:


  5. Add to queue Again


  6. Try to open queue item details.


     

     

    Error Message:

Dependency Records Error while importing Managed Solution

Error While Importing Managed Solution in CRM 2011:

Error:

Found 2 dependency records where unmanaged component is the parent of a managed component. First record (dependentcomponentobjectid = a7f9b236-452f-e211-aa3e-00155dc87c5a, type = AttributeMap, requiredcomponentobjectid = 8d4b6bc4-b4ed-e111-aba2-00155d018410, type= EntityMap, solution = b18c1343-ea7f-4eaa-abf7-31d81ade819c).

Cause:

The cause of above error it that there is custom Mapping between Managed Entity and Unmanaged Entity pre-existing in the system and system is not able to replace those mappings.

Resolution (More of a workaround):

  1. Unzip the managed solution.
  2. Edit customizations.xml, replace … tag inside with , Save.

    (Here you just removed all mappings)

  3. Zip the solution, Import it.
  4. Import Original Managed Solution solution. à Pay attention here you imported solution twice. Once without mappings, Once with that.

Thanks to Kjell L for the solution.

“AuditPFN” Issue while restoring MS Dynamics CRM 2011 Database Backup

While restoring CRM 2011 Database if you face following Error:

Error:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
Database ‘DatabaseName’ cannot be started in this edition of SQL Server because it contains a partition function ‘AuditPFN’. Only Enterprise edition of SQL Server supports partitioning. Database ‘DatabaseName” cannot be started because some of the database functionality is not available in the current edition of SQL Server. (Microsoft SQL Server, Error: 905).

Cause:

The cause of above exception is the SQL Server you are importing from is SQL Server Enterprise Edition but SQL Server you are importing to is not same.

While creating Org in SQL Server Enterprise Edition a partition is created in the DB for auditing purpose. The AuditBase table uses partition which is available only in Enterprise Edition.

Resolution:

  1. Backup (1) SQL DB from where you want to take backup to restore 😉 (Used in case you messup anything in SQL)
  2. Run given script against that DB.

[sourcecode language=”sql”]

IF EXISTS (SELECT name FROM sys.partition_schemes WHERE name=’AuditPScheme’) BEGIN SELECT   CASE WHEN ind.type != 1    THEN     ‘DROP INDEX [dbo].[AuditBase].’ + QUOTENAME(ind.name) + ‘ ‘    ELSE ‘ ‘   END +   ‘CREATE ‘ + CASE is_unique WHEN 1 THEN ‘UNIQUE ‘ ELSE ” END  +   ind.type_desc + ‘ INDEX ‘ + QUOTENAME(ind.name  COLLATE SQL_Latin1_General_CP1_CI_AS )  + ‘ ON [dbo].’ +  QUOTENAME(OBJECT_NAME(object_id)) + ‘ (‘ +      REVERSE(SUBSTRING(REVERSE((    SELECT name + CASE WHEN sc.is_descending_key = 1 THEN ‘ DESC’ ELSE ‘ ASC’ END + ‘,’    FROM     sys.index_columns sc     JOIN sys.columns c ON sc.object_id = c.object_id AND sc.column_id = c.column_id    WHERE     OBJECT_NAME(sc.object_id) = ‘AuditBase’ AND     sc.object_id = ind.object_id AND     sc.index_id = ind.index_id    ORDER BY index_column_id ASC    FOR XML PATH(”)         )), 2, 8000)) + ‘)’ +   CASE WHEN ind.type = 1    THEN     ‘ WITH (DROP_EXISTING = ON) ON [PRIMARY]’    ELSE     ‘ ‘   END  as Script INTO #indexesScript FROM sys.indexes ind JOIN sys.partition_schemes ps on ind.data_space_id=ps.data_space_id WHERE   OBJECT_NAME(object_id) = ‘AuditBase’   AND ps.name = ‘AuditPScheme’   AND is_unique_constraint = 0 SELECT * FROM #indexesScript   DECLARE @recreateScript nvarchar(max) DECLARE indScript CURSOR FOR SELECT Script FROM #indexesScript OPEN indScript FETCH NEXT FROM indScript INTO @recreateScript   WHILE @@FETCH_STATUS = 0   BEGIN     BEGIN TRANSACTION t1   Execute sp_executesql @recreateScript     IF @@ERROR > 0   BEGIN    ROLLBACK TRAN t1    declare @message varchar(max)    set @message = ‘Audit history recreate index failed. SQL: ‘ + @recreateScript       RAISERROR (@message, 10,1)   END   ELSE   BEGIN    COMMIT TRAN   END   FETCH NEXT FROM indScript INTO @recreateScript   END   DROP PARTITION SCHEME AuditPScheme DROP PARTITION FUNCTION AuditPFN   CLOSE indScript   DEALLOCATE indScript DROP TABLE #indexesScript END

[/sourcecode]

3. Backup (2) DB again (Used for import on you non Enterprise Edition SQL Server)

4. Restore the above backup [Backup (2)].

Not My solution J Just found Online here.

Microsoft Dynamics CRM 2011 Developer Tool Kit.

Being a CRM Developer for Microsoft Dynamics CRM 2011 its always frustrating to make customizations and then publish the content or to export the solution unzip it and then zip it and Export it back to the CRM. Microsoft has again taken a step to make your life easier (as it always does) and has released a Visual Studio plugin for you. In the latest CRM SDK you can find Developertoolkit in tools folder and this can be used to create plugins, silverlight webresources, make changes in solution and Deploy it to the CRM server all using CRM explorer in your Visual Studio.

You can download latest CRM SDK from http://www.microsoft.com/download/en/details.aspx?id=24004

MS Dynamics CRM : First Stupid Issue

I’ve just started Learning Microsoft Dynamics CRM. I know CRM 2011 is out but its certification is not. So I planned on learning CRM 4.0 first so that I can be certified :)

While learning I have just reached Page 1-6 of student manual for Configuration and customization and I am stuck up on an error while creating the user.

I am creating a new user and I’ve entered my data in the textbox and it is giving following error.

So from error it is clear that before adding a user to CRM it should be available in domain :) .

Cool so from above: Simple solution.. Go to Active Directory Users and Computers (in Administrative template). Create a new user, Now in CRM add user with same logon name as that in active directory and BINGO………. It gives the same error :) …..

Ok now add domain infront of logon i.e. / and its a BINGO :) .

Cool simple issue with more than simple resolution, but one question : Why we can’t add any user who are not there in any domain. May be thats too stupid to be a question to ask as if user is not there in AD you can’t authenticate it then it will be an issue with security and BLAH BLAH BLAH …… but still one day I’ll look into this issue : Is it feasible to add users in CRM who are not in active directory and If yes HOW? and if no HOW to make it feasible ?

But right now the highest priority is to learn CRM enough to complete certification (without dumps ofcourse…. other wise I would be sitting in some pub with Beer and not caring about this stupid stuff here )

Ok Forum….. Bbyeeeeee……… will be soon back with other weirdo and stupid issue :D .

MS Dynamics CRM : First Stupid Issue

I’ve just started Learning Microsoft Dynamics CRM. I know CRM 2011 is out but its certification is not. So I planned on learning CRM 4.0 first so that I can be certified :)

While learning I have just reached Page 1-6 of student manual for Configuration and customization and I am stuck up on an error while creating the user.

I am creating a new user and I’ve entered my data in the textbox and it is giving following error.

So from error it is clear that before adding a user to CRM it should be available in domain :) .

Cool so from above: Simple solution.. Go to Active Directory Users and Computers (in Administrative template). Create a new user, Now in CRM add user with same logon name as that in active directory and BINGO………. It gives the same error :) …..

Ok now add domain infront of logon i.e. / and its a BINGO :) .

Cool simple issue with more than simple resolution, but one question : Why we can’t add any user who are not there in any domain. May be thats too stupid to be a question to ask as if user is not there in AD you can’t authenticate it then it will be an issue with security and BLAH BLAH BLAH …… but still one day I’ll look into this issue : Is it feasible to add users in CRM who are not in active directory and If yes HOW? and if no HOW to make it feasible ?

But right now the highest priority is to learn CRM enough to complete certification (without dumps ofcourse…. other wise I would be sitting in some pub with Beer and not caring about this stupid stuff here )

Ok Forum….. Bbyeeeeee……… will be soon back with other weirdo and stupid issue :D .