locked
How to retrieve custom entity / Convert in custom entity RRS feed

  • Question

  • Hi,

     

    I need some help. I'm trying to make some modifications on a custom entity. But I can only find code for a system entity which means that the retrieve-functions gives me a BusinessEntity. The error is that the BusinessEntity cannot be converted to my custom entity?

    Is there a workaround for this?

     

    Your help is very much appreciated.


    Thanks, best regards,

     

    Daniel Popp

    Thursday, February 14, 2008 5:07 PM

Answers

  • Ok, that was it!

    I also needed to add crm4.AllColumns() but now it works.

    Thanks to all,


    Daniel

    Friday, February 15, 2008 11:17 AM

All replies

  • Hi.

     

    A System Entity is an entity witch is not customizable and is part of the Microsoft CRM Vanilla.

    A Customizable Entity is also an entity that you get out of the box but can be customized.

    A Custom entity is an Entity witch you add to address your business needs.

     

    The BusinessEntity Class is the parent class for all entities.

    When using Retrieve Simply Cast to the desired entity and use its properties like this:

     

    account Account = businessEntity as account;

    OR

    account Account = (account)businessEntity;

     

    Console.WriteLine( Account.name );

     

    Cheers,

    Adi

     

    Thursday, February 14, 2008 6:54 PM
  • Hi Adi,

     

    thanks for your help.

    But I still have the problem:

    This code works:

    account myaccount = (account)service.Retrieve(EntityName.account.ToString(), myaccountid, new AllColumns());


     

    This code doesn't work cause I get an error in Visual Studio: (crm4 is here used as a webrefernce to the server)

    crm4.new_test myTest = (crm4.new_test)service.Retrieve(crm4.EntityName.new_test.ToString(), myTestId, new AllColumns());

     

    The error is:

    Convertion from "Microsoft.Crm.Sdk.BusinessEntity" in "Class.crm4.new_test" is not possible.

     

    Does anyone know how to handle this? I want to write a plugin for a custom entity new_test.

    Thanks a lot!!


    Daniel

    Friday, February 15, 2008 8:33 AM
  •  Daniel Popp wrote:
    The error is:

    Convertion from "Microsoft.Crm.Sdk.BusinessEntity" in "Class.crm4.new_test" is not possible.

    The BusinessEntity class that is used there is not the one which your new_test class is derived from, because it is in a completely different namespace, so of course that cast is not possible. Try removing the reference to Microsoft.Crm.Sdk; your crm4 namespace should have its own BusinessEntity class.


    To make that clearer - it appears that you are using two different instances of the web service, and your application each time picks the first one in which it can find a given name.

    Friday, February 15, 2008 9:43 AM
  • Hi GCATNM,

     

    how do I solve it? I need the microsoft.crm.sdk for several functions but I also need the web reference because ohterwise my custom entity new_test wouldn't be recognized.

    Is there maybe a code sample?

     

    Daniel

     

    Friday, February 15, 2008 10:13 AM
  • As I said, it seems to me that you are using two instances of the CRM web service, one is Microsoft.Crm.Sdk, and one is crm4 (which also seems to be the up-to-date one). If I'm correct, your crm4 namespace can do everything you need, and you don't need the Microsoft.Crm.Sdk at all. Just try commenting out the using Microsoft.Crm.Sdk; line and look what happens.
    Friday, February 15, 2008 10:22 AM
  • I haven't integrated the crm4 in the project with a using-command. crm4 is the name of my web reference which is linked to the http://myServer/mscrmservices/2007/CrmServiceWsdl.aspx so that I have access to the new custom entities.

    If I integrated crm4 with a using-command, VS is confused which web service to use. (as you described)

     

    Also if I didn't use Microsoft.Crm.Sdk, VS wouldn't find several classes as IPlugin. (this doesn't change when I add the using command: using myProject.crm4Wink

     

    Thanks,

    Daniel

    Friday, February 15, 2008 10:55 AM
  • Hi.

     

    Simply create an instance of crm4.CrmService and use its Retrieve Method.

     

    crm4.CrmService crm4Service = new crm4.CrmService();

    // don't forget your Credentials.

    crm4.new_test myTest = (crm4.new_test)crm4Service.Retrieve(crm4.EntityName.new_test.ToString(), myTestId, new AllColumns());

     

    Adi

    Friday, February 15, 2008 11:09 AM
  • Ok, that was it!

    I also needed to add crm4.AllColumns() but now it works.

    Thanks to all,


    Daniel

    Friday, February 15, 2008 11:17 AM
  • For me, I do not have a crm4.. only

    IPluginExecutionContext

    context which I get

    ICrmService service = context.CreateCrmService(true);

     

    Also in this I have only what there is by default. No new entities, no new attributes... how do i generate a crm4 ?

    In 2011 we can do

    crmsvcutil /url:http://localhost/ScribeOrg1/XRMServices/2011/Organization.svc /out:C:\GeneratedCode.cs /username:Administrator /password:pass@word1

    But i do not know how to do in version 4.

    Anyone can help ?thanks


    Bernard Lessard
    Monday, October 17, 2011 5:40 PM