Showing posts with label CRM plug-in. Show all posts
Showing posts with label CRM plug-in. Show all posts

Thursday, 7 June 2012

Update status in CRM 2011

Here is the code to update a recode via CRM context object:

CRMContext.Execute(new SetStateRequest
            {
                EntityMoniker = new EntityReference
                {
                    Id = new Guid(""),
                    LogicalName = "" //Entity Name
                },
                State = new OptionSetValue(1), //get the value
                Status = new OptionSetValue(1)
            }
            );

Thursday, 22 March 2012

The context is not currently tracking the entity

I encountered this error when I deploy a plug-in to CRM online environment. I tested the same plug-in in on premises environment and it works without any error.

The plugin read and write to entity A and entity B (they have no relationships). The plug-in is triggered when entity A records are created and it retrieve all records from entity B and process them.

The error was thrown when it tries to save changes to entity B, with this error message: The context is not currently tracking the <<entity B>> entity

It suggested the services context does not track <<entity B>> in the scope. I researched this topic and found out I need to use OrganizationServiceContext.Attach Method. However when I use this method it returns with this error: The context is already tracking the <<entity B>> entity. :(

And did more research and found that it actually need to detach the object ( OrganizationServiceContext.Detach Method) before it can be attached.

This makes no sense to me but this is the work around.

Tuesday, 13 March 2012

CRM 2011 Plug-in error: Object reference not set to an instance of an object.


Problem/Error:
When I create an instance of object from the sdk generated code by using the default constructor like:
email.regardingobjectid = new CrmEntityReference();
I will find it return a null object:




This is not the result I wanted because the object does not have correct structure and when I try to assign a value to the object (in this case is regardingobjectid) it will throw a NullReferenceException error like this:
Solution
The solution is relatively simple by using a different constructor and it will give a correct object:
email.regardingobjectid = new CrmEntityReference("contact", contact.contactid);

Saturday, 31 December 2011

CRM Online can't find Microsoft.Xrm.Client.dll

Hi all,

Today I was writing (and I am still) a Plug-in for CRM online 2011 and counter a error as:
Could not load file or assembly 'Microsoft.Xrm.Client, Version=5.0.9688.1154, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
It happens because in my project I reference to Microsoft.Xrm.Client.dll and in the CRM online server this DLL is not installed.

I think this client dll is not intended to be used in server environment and therefore is not installed in CRM server.

I founded the generated code from crmsvcutil actually required the client dll if you include following parameter in your generation command .
/codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration"
I re-generated the code file from crmsvcutil without the parameter and reload the project with an updated code file (Xrm.cs), recompile the project and it works :)

By the way, Happy 2012 :)