Wednesday, October 10, 2012

Execute FetchXML in CRM 2011

If you want to execute arbitrary fetchXML code, dont forget about the bids reporting extension.

While developing some custom code best suited to a fetchXML query, I wanted a rapid way to execute fetchXML for a complex query. A small test app would work, and there is even a simple codeplex project for exactly that here http://crm2011fetchexecute.codeplex.com/. However I recalled executing fetxhXML in the CRM 2011 bids reporting extension so if you have that installed simply open one of your CRM based reports and make a new dataset and use the query designer there to help debug those complex fetxhXML statements!


Thursday, September 13, 2012

CRM 2011 Online Programatic Report Generation

CRM 2011 Online Programatic Report Generation isnt possible through the API.

Microsoft knows about the feature gap. They recommend we vote for it on connect. This is the highest voted item in connect for it: give it a vote with your live id?

My scenario is for a customer who wants to auto create order reports and email them -- I have no solution other than recommending they move to on-premise.

UPDATE!

We want to generate Reports programmatically in a CRM-online environment (exported to PDF and/or word).

There appears to be a way to achieve this in a crm-online environment posted in this blog: http://xrmmatrix.blogspot.ca/2011/06/creating-report-as-pdf-attachment-in.html The logic behind it looks like it should work – since you can perform these actions via the web interface they must resolve into requests and responses so we can use XMLHttpRequests to get the data. The blog has many comments so it looks like the pitfalls have been addressed. 

Friday, June 15, 2012

CRM 2011 - Activity Party and SerializationException in plugins

I was working with the requiredattendees on the appointment entity and ran into a miserable time with a serialization exception. Funny thing was the exception is only thrown when I registered my plugin as isolation (aka sandbox) mode. No one seemed to have a post on the exact same issue so here's how I solved it:


I found an article about it that suggested removing all references to the activityparty svcutil generated class: http://nicolagrillo.blogspot.ca/2012/01/crm-2011-activityparty.html

That did not work, but I have not tried completely removing all reference to the class in my assembly as that is an unrealistic solution in my situation.
My error from the server trace: important part extracted for visibility:
System.Runtime.Serialization.SerializationException: Element 'http://schemas.microsoft.com/xrm/2011/Contracts:Entity' contains data from a type that maps to the name 'MyNamespace:ActivityParty'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'ActivityParty' and namespace 'MyNamespace'.
>System.Runtime.Serialization.SerializationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #5BCA670D: System.Runtime.Serialization.SerializationException: Element 'http://schemas.microsoft.com/xrm/2011/Contracts:Entity' contains data from a type that maps to the name 'MyNamespace:ActivityParty'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'ActivityParty' and namespace 'MyNamespace'.
>   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
>   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
>   at ReadArrayOfEntityFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString , XmlDictionaryString , CollectionDataContract )
>   at System.Runtime.Serialization.CollectionDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
>   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
>   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
>   at ReadKeyValuePairOfstringanyTypeFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
>   at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
>   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
>   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
>   at ReadAttributeCollectionFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString , XmlDictionaryString , CollectionDataContract )
>   at System.Runtime.Serialization.CollectionDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
>   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
>   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
>   at ReadEntityFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
>   at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
>   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
>   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
>   at ReadKeyValuePairOfstringanyTypeFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
>   at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
>   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
>   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
>   at ReadParameterCollectionFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString , XmlDictionaryString , CollectionDataContract )
>   at System.Runtime.Serialization.CollectionDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
>   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
>   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)
>   at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
>   at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
>   at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlDictionaryReader reader)
>   at Microsoft.Crm.Sandbox.SandboxUtility.DeserializeDataContract[T](Byte[] serializedDataContract, Assembly proxyTypesAssembly)
>   at Microsoft.Crm.Sandbox.SandboxPluginExecutionContext.get_InputParameters()
>   at Microsoft.Crm.Sandbox.SandboxPluginExecutionContext.Merge(IPluginExecutionContext originalContext)
>   at Microsoft.Crm.Sandbox.SandboxPlugin.Execute(IServiceProvider serviceProvider)
I am very curious why it fails in isolation mode and works in non isolation. I hope the stack trace triggers a thought from someone.

Ultimately it turns out you cannot use the early bound classes when you want to assign to the target entity when you are in this context. I still don't complete understand what the context is that causes this error, because I use early bound classes in sandboxed plugin steps all the time, often assigning them into the target entity input parameter. Michael from microsoft has more detail here: http://social.microsoft.com/Forums/eu/crmdevelopment/thread/0b4d4d0f-0428-4964-9ce8-b86c89817974