Category: CRM 2011

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]

Error While Refreshing CRM 2011 Main Page Grid – UR 12

In our CRM 2011 ribbon we had written code to Refresh the Grid after click of a ribbon button.

It was like

crmGrid.Refresh(); or you might have implemented it like document.getElementById(“crmGrid”).Refresh();

After updating to UR 12 we were getting an error on crmGrid object.

“Object doesn’t support property or method ‘Refresh'”

After looking into DOM (for long-long time) we found that the Refresh method has been moved inside control class, so it can Now be implemented as

crmGrid.control.Refresh();

The operation ‘*************Async’ could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.

We were getting Below given error in all our environments except one.

Searching on net gave various reasons for this error like : DataContract if used in WCF Service then gives exception if you return with primitive type etc…

None of those criteria fit it as it was working fine in One CRM environment.

Reason
for this error was that Plugin was built against .Net framework 4.5 but servers Giving error had framework 4.0.

So to resolve
this we can either upgrade server to 4.5 (as it worked in one environment with Framework 4.5) or we can Build plugins against Framework 4.0.

“The operation ‘*************Async’ could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.”

The Web Service plug-in failed in OrganizationId: d7e722c9-6fa5-4bac-8ec3-05174cd4c8db; SdkMessageProcessingStepId: eb06f709-1ecd-e211-bd85-00155d885d81; EntityName: ******; Stage: 40; MessageName: Create; AssemblyName: ****************************, ************.Plugins, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c1b635ad77c3aa7c; ClassName: *****************; Exception: Unhandled Exception: System.InvalidOperationException: The operation ‘*************Async’ could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.

   at System.ServiceModel.Dispatcher.OperationFormatter.Validate(OperationDescription operation, Boolean isRpc, Boolean isEncoded)

   at System.ServiceModel.Dispatcher.OperationFormatter..ctor(OperationDescription description, Boolean isRpc, Boolean isEncoded)

   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter..ctor(OperationDescription description, DataContractFormatAttribute dataContractFormatAttribute, DataContractSerializerOperationBehavior serializerFactory)

   at System.ServiceModel.Description.DataContractSerializerOperationBehavior.GetFormatter(OperationDescription operation, Boolean& formatRequest, Boolean& formatReply, Boolean isProxy)

   at System.ServiceModel.Description.DataContractSerializerOperationBehavior.System.ServiceModel.Description.IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy)

   at System.ServiceModel.Description.DispatcherBuilder.BindOperations(ContractDescription contract, ClientRuntime proxy, DispatchRuntime dispatch)

   at System.ServiceModel.Description.DispatcherBuilder.BuildProxyBehavior(ServiceEndpoint serviceEndpoint, BindingParameterCollection& parameters)

   at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose)

   at System.ServiceModel.ChannelFactory.CreateFactory()

   at System.ServiceModel.ChannelFactory.OnOpening()

   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)

   at System.ServiceModel.ChannelFactory.EnsureOpened()

   at System.ServiceModel.ChannelFactory1.CreateChannel(EndpointAddress address, Uri via)

   at System.ServiceModel.ClientBase1.CreateChannel()

   at System.ServiceModel.ClientBase1.CreateChannelInternal()

   at System.ServiceModel.ClientBase1.get_Channel()

   at *****************.BusinessProcess.EmailService.Service1SoapClient.*****************.BusinessProcess.EmailService.Service1Soap.SendSingleEMAIL(SendSingleEMAILRequest request)

   at *****************.BusinessProcess.EmailService.Service1SoapClient.SendSingleEMAIL(String userName, String password, String mobileNumber, String contenet)

   at *****************.BusinessProcess.XrmNew_Email.SendMessage(new_Email EmailContext, IOrganizationService service)

   at *****************.Plugins.PostEMAILCreateSendEMAIL.ExecutePostEMAILCreate(LocalPluginContext localContext)

   at *****************.Plugins.Plugin.Execute(IServiceProvider serviceProvider)

   at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context)

   at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)

Queue Item Work On vs. Case Assign

.

  1. When we say Assign on a particular CRM Case then it changes the Owner of the case.

     

     

    But when we say “Work on” on a “Queue Item” then it updates “Worked By” field in “Queue Item Details” rather than changing the owner of the case.

     

     

    Many a times mistake is made in considering these functionalities as same and can lead to design flaws in Application.

     

  2. When a case is assigned “Assign” message is triggered for a plugin but when we “Work On” from “Queue”, Update message is triggered on “Queue Item”.

     

  3. Out of the box CRM 2011 doesn’t provide any functionality to keep these both in sync so custom code (plugin) will be required to keep both these values in sync.

     

  4. If you want to move a case to user queue when it is assigned to user you can use out of the box feature of case entity (but it is not same as keeping work on and assigned to in sync as it is limited till a user queue only)

     

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:

Import Solution Issue in UR 12

Recently we tried to import solution on CRM which was recently updated from UR 6 to UR 12.

Solution we had was taken from same server from a different org (after upgrade) and was getting stuck at the import step with no activity (at all) in progress bar.

Following Exception was there in CRM Trace log viewer

at CrmException..ctor(Int32 errorCode, Object[] arguments) ilOffset = 0x36

at SolutionImportProcessPage.ProcessRequestData() ilOffset = 0x4A

at SolutionImportProcessPage.ProcessAction(String action) ilOffset = 0x92

at AppUIPage.OnPreRender(EventArgs e) ilOffset = 0xD

at Control.PreRenderRecursiveInternal() ilOffset = 0x54

at Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) ilOffset = 0x6D3

at Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) ilOffset = 0x3C

at Page.ProcessRequest() ilOffset = 0x14

at Page.ProcessRequest(HttpContext context) ilOffset = 0x31

at CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() ilOffset = 0x18D

at HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) ilOffset = 0x15

at ApplicationStepManager.ResumeSteps(Exception error) ilOffset = 0x10A

at HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) ilOffset = 0x5C

at HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) ilOffset = 0x16A

at ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType) ilOffset = 0x4B

>Crm Exception: Message: An error occurred while importing a Solution., ErrorCode: -2147188685

To resolve this following post from Microsoft discussion forum helped

http://social.microsoft.com/Forums/en-US/crmdeployment/thread/755b7161-4ec3-40d1-bc37-776460656d9e

  1. Stop Async Service in services.msc
  • Run “services.msc”
  • Stop Async Service

     

2.  Take Microsoft.crm.sdk.proxy.dll from latest sdk

3.  Open Visual studio command line tools (in administrator privileges)

Run

gacutil /i c:sdkbinMicrosoft.crm.sdk.proxy.dll

do

4.  IIS reset, restart CRM Async Service in services.msc

Try importing the solution

 

PS: If you are in a farm deployment then Install Microsoft,crm.sdk.proxy.dll in the server running CRM Async Service.

Before installing dll, stop the async service, install dll in gac and restart async service.

 

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.