locked
Handling custom attributes belonging to system entities (4.0) RRS feed

  • Question

  • Using the SDK, I can see that to create a new system entity record I'd use Create(account) but how do I handle the setting of custom attributes belonging to system entities, e.g. account, contacts etc ? Should I be using TargetCreateDynamic? I can't see any examples out there but then maybe I'm missing something. Any help is appreciated.
    Monday, April 20, 2009 3:59 PM

Answers

  • You would set the custom attribute just as you would a system attribute.  If you are using the Create(account) message and you don't see your custom attributes listed, make sure the customizations are published and then update the CRM web reference in your code.  There is sample code in the sdk for setting attributes for dynamic entities in the SDK, under server\howto\vb or cs\dynamicentityhowto.

    • Marked as answer by Chevva Tuesday, April 21, 2009 10:38 AM
    Monday, April 20, 2009 4:17 PM

All replies

  • Hi,

    If you are using CrmService created using CreateCrmService() method of context object within your plugin, you would have to use DynamicEntity class for setting values for custom attributes.

    However if your are using CrmService by adding web references to it, you could find your custom attributes like your system attributes and could set their value.

    Regards,
    Nishant Rana
    http://nishantrana.wordpress.com
    Monday, April 20, 2009 4:17 PM
  • You would set the custom attribute just as you would a system attribute.  If you are using the Create(account) message and you don't see your custom attributes listed, make sure the customizations are published and then update the CRM web reference in your code.  There is sample code in the sdk for setting attributes for dynamic entities in the SDK, under server\howto\vb or cs\dynamicentityhowto.

    • Marked as answer by Chevva Tuesday, April 21, 2009 10:38 AM
    Monday, April 20, 2009 4:17 PM
  • Thanks a lot for the pointers. After publishing/updating the webservice I didn't get to see the new custom attributes. However, as I'm already using TargetCreateDynamic for complete custom entities, I simply changed this to point at a system entity (account), created then added an array of dummy custom attributes followed by service.Execute(create) and it all works. I guess I'm now asking if this is best practice...
    Monday, April 20, 2009 4:50 PM
  • What is the url you are pointing your web reference to?  Because of the capability of multi-tenancy, you have to add the orgname on to the url to be able to see the specific attributes of that organization, like this: 

    http://crm:5555/mscrmservices/2007/crmservice.asmx?uniquename=OrgUniqueName

    Replace OrgUniqueName with your unique orgname, and it is case sensitive.

    The SDK lists the best practice as creating Strong Types, not dynamic entities.  I prefer dynamic entities because I generally don't know the names of attributes or entities at design time and I need the flexibility offered by dynamic entities.

    Monday, April 20, 2009 5:01 PM
  • Hi,

    Normally we would be using TargetCreateDynamic class if we are writing a piece of resusable code or  a function which would create records of different entity based on the name of the entity passed.

    Regards,

    Nishant Rana
    http://nishantrana.wordpress.com
    Monday, April 20, 2009 5:37 PM
  • Hi,

    If you are creating in Plugin:

    DynamicEntity deAccount=new DynamicEnity("account");
    
    deAccount["name"] = "AccountName";
    deAccount["new_picklistattribute"] = new Picklist(1);
    deAccount["new_lookup"] = new Lookup("entityname",guid);
    
    
    ICrmService crmService = context.CreateCrmService(true);
    Guid accountid = crmService.Create(deAccount);
    


    Cheers!
    Tuesday, April 21, 2009 8:35 AM
  • Great responses everyone, - Thanks!
    Tuesday, April 21, 2009 10:40 AM