locked
Getting an entity's custom attributes RRS feed

  • Question

  • Hi all,

    I need to get ONLY the entity's custom attributes...
    now, i don't know the name of those attributes (only that they start with the word new_) or even if there are any.

    i know that by using a dynamic entity i can get those... but it comes in addition to all the other attributes.
    is there a way to remove the constant ones and get ONLY the custom ones?

    oh... and I'm using c# if that's matter... :)

    Thanks!
    Ohad
    Wednesday, February 25, 2009 3:44 PM

Answers

  • Hi

    You can either get all columns, and filter on the propertybag of the dynamic entity (using Linq or a foreach loop on the propertycollection AsEnumerable), or you can use the metadataservice to get the attributes names, use this list as values in the columnset.

    Don't know of any other ways.

    Best regards
    Jens
    • Marked as answer by OhadOr Monday, March 2, 2009 10:36 AM
    Thursday, February 26, 2009 8:43 AM
  • The beauty of using DynamicEntity is that it can work with entities that do not exist at design time. It does not require WSDL regeneration when schema changes.

    Yes you can access the value with properties["propertyname"] or simply entity["propertyname"].

    //Retrieve the Loan Application Entity  
    DynamicEntity loanEntity;  
    {  
        //Create the target  
          
        TargetRetrieveDynamic retrieveTarget = new TargetRetrieveDynamic();  
        retrieveTarget.EntityId = loanApplication.Value;  
        retrieveTarget.EntityName = loanApplication.type;  
     
        //Create a request  
        RetrieveRequest retrieveRequest = new RetrieveRequest();  
        retrieveRequest.ColumnSet = new ColumnSet(new string[] { "new_loanapplicationid""new_loanapplicantid" });  
        retrieveRequest.ReturnDynamicEntities = true;  
        retrieveRequest.Target = retrieveTarget;  
     
        //Execute the request  
        RetrieveResponse retrieveResponse = (RetrieveResponse)service.Execute(retrieveRequest);  
     
        //Retrieve the Loan Application Entity  
        loanEntity = retrieveResponse.BusinessEntity as DynamicEntity;  
    }  
     
    TargetRetrieveDynamic retrieveTarget = new TargetRetrieveDynamic();  
    retrieveTarget.EntityId = ((Lookup)loanEntity["new_loanapplicantid"]).Value; 

    Ronald
    • Marked as answer by OhadOr Monday, March 2, 2009 10:36 AM
    Thursday, February 26, 2009 6:22 PM

All replies

  • Hi

    You can either get all columns, and filter on the propertybag of the dynamic entity (using Linq or a foreach loop on the propertycollection AsEnumerable), or you can use the metadataservice to get the attributes names, use this list as values in the columnset.

    Don't know of any other ways.

    Best regards
    Jens
    • Marked as answer by OhadOr Monday, March 2, 2009 10:36 AM
    Thursday, February 26, 2009 8:43 AM
  • ok. so i retrieved the custom entities names (schema and display names).
    now i want to retrieve their value for each entity...

    i use a queryexpression to retrieve all the entities data..
    but how can i read the certain custom enetity value...?
    the webservice is not compiled for each server i connect and therefore will not be familiar with that custom field.
    is there a properties["propertyname"] or something of this sort to read this field's value?


    Thanks,
    Ohad


    ohad
    Thursday, February 26, 2009 3:48 PM
  • The beauty of using DynamicEntity is that it can work with entities that do not exist at design time. It does not require WSDL regeneration when schema changes.

    Yes you can access the value with properties["propertyname"] or simply entity["propertyname"].

    //Retrieve the Loan Application Entity  
    DynamicEntity loanEntity;  
    {  
        //Create the target  
          
        TargetRetrieveDynamic retrieveTarget = new TargetRetrieveDynamic();  
        retrieveTarget.EntityId = loanApplication.Value;  
        retrieveTarget.EntityName = loanApplication.type;  
     
        //Create a request  
        RetrieveRequest retrieveRequest = new RetrieveRequest();  
        retrieveRequest.ColumnSet = new ColumnSet(new string[] { "new_loanapplicationid""new_loanapplicantid" });  
        retrieveRequest.ReturnDynamicEntities = true;  
        retrieveRequest.Target = retrieveTarget;  
     
        //Execute the request  
        RetrieveResponse retrieveResponse = (RetrieveResponse)service.Execute(retrieveRequest);  
     
        //Retrieve the Loan Application Entity  
        loanEntity = retrieveResponse.BusinessEntity as DynamicEntity;  
    }  
     
    TargetRetrieveDynamic retrieveTarget = new TargetRetrieveDynamic();  
    retrieveTarget.EntityId = ((Lookup)loanEntity["new_loanapplicantid"]).Value; 

    Ronald
    • Marked as answer by OhadOr Monday, March 2, 2009 10:36 AM
    Thursday, February 26, 2009 6:22 PM