locked
add atrributes as an array in mscrm 2011 when creating new record RRS feed

  • Question

  • Dear all;

    as we know that when we create new record throguh plugin we add field names and value for example 

    Entity account= new Entity();

    account["name"]="abc"

    service.create(account);

    can we do in a way like 

    we have array of fields

    Account[1]="abc"

    service.create(Account);

    Monday, February 17, 2014 2:48 PM

Answers

  • That's not impossible since the attributes of the entity are not stored in no particular order like columns of the datatable.

    The closest thing that I could think of is declaring a readonly string array beforehand.

    public readonly string[] accountAttrib = { "name", "accountnumber", "email", "website" };
    Entity account = new Entity("account");
    account[accountAttrib[0]] = "abc";
    account[accountAttrib[1]] = "12345";
    account[accountAttrib[2]] = "test@abc.com";
    account[accountAttrib[3]] = "www.abc.com";
    service.create(account);

    Monday, February 17, 2014 4:27 PM