locked
entity.Attributes.Keys.ElementAt(i) is not available in MS CRM 2011 RRS feed

  • Question

  • Hi All,

    I was trying to convert the below code(ms crm 4.0) to MS CRM 2011 format. but for the statement "if (response.Properties[i].Name.ToLower() == "new_phone") " proper properties are not avialable to convert. Could you please provide the solution for this.

    I tried with response.Attributes.Keys.ElementAt(i) but .ElementAt is not available.

    DynamicEntity response = (DynamicEntity)be;

    for (int i = 0; i < response.Properties.Length; i++) {

    if (response.Properties[i].Name.ToLower() == "new_phone") {

    }

    }

    Thanks

    Srikanth Reddy

    Friday, November 7, 2014 2:52 PM

All replies

  • Not getting, what actually you need...
    seems you looking for the statement:

    response.Attributes["new_phone"];

    OR

    response.GetAttributeValue<string>("new_phone");


    Friday, November 7, 2014 3:23 PM
  • which exact object is "response"? in CRM 2011 will be an entity but what are you retrieving?

    My blog: www.crmanswers.net - Rockstar 365 Profile

    Friday, November 7, 2014 3:24 PM
  • I am looking for response.Attributes.Keys.ElementAt(i)

    but ElementAt object is not there in MS CRM 2011 and response is the "Entity" type..

    And also  I am trying to get the attribute name using for loop like response.Attributes.GetType().Name but how to in for loop..

    Friday, November 7, 2014 3:33 PM
  • I asked what are you retrieving.

    However if you want to check if an attribute is inside the entity you can use Contains

    if (response.Contains("new_phone")) {
        string phone = response.GetAttributeValue<string>("new_phone");
    }


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Friday, November 7, 2014 3:41 PM
  • Here it is, what you want... Try it.

    response.Attributes.ToList().ElementAt(0).Key

    it will return "new_phone" or whatever the attribute name is...

    Friday, November 7, 2014 5:15 PM
  • Hi All,

    I am not finding the method .ToList() for Attributes object. is there anyway to get the attribute name of the entity.

    Actually in MS CRM 4.0 it is like the below code.

    for (int i = 0; i < response.Properties.Length; i++) {

    if (response.Properties[i].Name.ToLower() == "new_phone") {

    }

    }

    But how can we write in MS CRM 2011 response the Entity object here.

    It would be great If anybody can provide the solution for this.

    Thanks

    Srikanth Reddy

    Sunday, November 9, 2014 8:24 AM
  • what is the error on writing ToList() for Attributes object?

    I tried myselft, and it is working in my board...

    Entity response = responseFromXyzLocation; //This responce must be of Entity type.

    AttributeCollection attributeCollection = response.Attributes; //This "Attributes" must be of AttributeCollection type.

    //If it is, then it should have to work:

    string nameFromArray = attributeCollection.ToArray().ElementAt(0).Key; // fetching from Array

    string nameFromList = attributeCollection.ToList().ElementAt(0).Key; // fetching from List


    • Proposed as answer by Piyush Parate Sunday, November 9, 2014 2:29 PM
    Sunday, November 9, 2014 2:29 PM
  • Hi

    Thanks for your response, still I am facing the same issue as you can see the below screenshot on the same.

    Monday, November 10, 2014 8:04 AM
  • try with

    Microsoft.Xrm.Sdk.AttributeCollection attributeCollection = response.Attributes;

    probably you have using System.ComponentModel; in your code and create an issue.


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Monday, November 10, 2014 8:43 AM
  • Hi tried with the solution which you have provided still facing the same issue. and also I am using System.ComponentModel;

    Monday, November 10, 2014 9:06 AM
  • Add reference:

    using System.Linq;

     
    Monday, November 10, 2014 10:53 AM