locked
Help "the given key was not in the dictionary" RRS feed

  • Question

  • Hi,

    Here is my code:

    ColumnSet attributes = new ColumnSet(true);
    Account retrievedsite = (Account)_serviceProxy.Retrieve("account", id, attributes);

    However, an error occurs "the given key was not in the dictionary"

    I also try this:

     ColumnSet attributes = new ColumnSet(new string[] { "accountnumber","name","address1_line2","adress1_line3","telephone1" });
    Account retrievedsite = (Account)_serviceProxy.Retrieve("account", id, attributes);

    Still the same error it does not recognize "address1_line2" and several other auttributs ...

    Do you know the problem?

    Thanks,

    Thursday, May 10, 2012 7:19 AM

Answers

  • one of your Attributes is most likely NULL (and therefore not present in the attributes dictionary).
    You need to use Contains() method of the object to check whether the key exist o not.

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
    Mubasher Sharif
    Check out my about.me profile!
    http://mubashersharif.blogspot.com
    Linked-In Profile
    Follow me on Twitter!


    • Edited by MubasherSharif Thursday, May 10, 2012 8:09 AM
    • Marked as answer by Jalix60 Thursday, May 10, 2012 8:23 AM
    Thursday, May 10, 2012 7:53 AM
  • you can check like below

    if(Entity.Attributes.Contains("AttributeName"))  //you need to change entity object name and attribute name.

    {

    //code to fetch value

    }


    Mahain : Check My Blog
    Follow me on Twitter
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Marked as answer by Jalix60 Thursday, May 10, 2012 8:23 AM
    Thursday, May 10, 2012 8:17 AM
    Moderator
  • Hi Jalix,

    At what point did the error occur? Did it occur when you call the Retrieve method?

    To answer your other question, yes you can update the attribute even though it is null when you retrieve it.

    All you need is to set the value. Eg: theAccount.address1_line1 = "Address Line"; 

    and call the organizationService.Update(theAccount);


    Dimaz Pramudya - CRM Developer - CSG (Melbourne) www.xrmbits.com http://twitter.com/xrmbits

    Thursday, May 10, 2012 10:15 AM

All replies

  • one of your Attributes is most likely NULL (and therefore not present in the attributes dictionary).
    You need to use Contains() method of the object to check whether the key exist o not.

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
    Mubasher Sharif
    Check out my about.me profile!
    http://mubashersharif.blogspot.com
    Linked-In Profile
    Follow me on Twitter!


    • Edited by MubasherSharif Thursday, May 10, 2012 8:09 AM
    • Marked as answer by Jalix60 Thursday, May 10, 2012 8:23 AM
    Thursday, May 10, 2012 7:53 AM
  • Hi,

    Make sure those fields are not Empty. Check this post

    http://social.microsoft.com/forums/en-us/crmdevelopment/thread/F5A19714-2501-4992-A4F5-8399E599C276

    HTH

    Thanks


    e-Biz


    • Edited by Harispk Thursday, May 10, 2012 7:56 AM
    Thursday, May 10, 2012 7:54 AM
  • How to use the Contains method to see if the attribute is empty?
    Thursday, May 10, 2012 8:12 AM
  • you can check like below

    if(Entity.Attributes.Contains("AttributeName"))  //you need to change entity object name and attribute name.

    {

    //code to fetch value

    }


    Mahain : Check My Blog
    Follow me on Twitter
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Marked as answer by Jalix60 Thursday, May 10, 2012 8:23 AM
    Thursday, May 10, 2012 8:17 AM
    Moderator
  • This means that you can not update an attribute which was empty at the base?
    Thursday, May 10, 2012 10:01 AM
  • Hi Jalix,

    At what point did the error occur? Did it occur when you call the Retrieve method?

    To answer your other question, yes you can update the attribute even though it is null when you retrieve it.

    All you need is to set the value. Eg: theAccount.address1_line1 = "Address Line"; 

    and call the organizationService.Update(theAccount);


    Dimaz Pramudya - CRM Developer - CSG (Melbourne) www.xrmbits.com http://twitter.com/xrmbits

    Thursday, May 10, 2012 10:15 AM
  • Hi,

    Thanks Mahender and Mubasher, i was forcing the attributes to "Business Required" to solve this error. 

    Thanks for your help.


    Haris Adil e-Biz

    Thursday, May 10, 2012 10:47 AM