web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

the given key was not present in the dictionary

(1) ShareShare
ReportReport
Posted on by 290

Hi All,

I am trying to update opportunity fields which is null in db. When i am retrieving the all records attributes are coming only which has data in field, if recodes fields has not data its not coming.

I want to update "processid" and "stageid fields in opportunity using console application. but its not comming the records because its null in database.

QE.ColumnSet = new ColumnSet("stepname", "processid", "stageid");
QE.EntityName = "opportunity";

When trying to update these feids giving error.

the given key was not present in the dictionary

Please let help me.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at
    RE: the given key was not present in the dictionary

    Hello,

    This error will come when you will try to access the fields which is not present in the property beg, not when when you will update them so for example let say processid field is not available in the entity's property beg so if you will try to access this field directly instead of check for null, you will get this error

    var processid=entity.GetAttributeValue<fielddatatype>("fieldname");

    But if you will try to use like below you won't get this error

    if(entity.Contains("fieldname"))  //in this case you won't get error here

    {

    var processid=entity.GetAttributeValue<fielddatatype>("fieldname");

    }

    Now to update you should use like below

    Entity entity=new Entity("entityname");

    entity["primaryfield"]="primarfield"; //this you can get it from the retrieved entity object

    Entity["fieldname"]=value;

    service.Update(entity);

  • Aileen Gusni Profile Picture
    44,524 on at
    RE: the given key was not present in the dictionary

    Mohammad,

    You can check first the field value using

    entity.GetAttributeValue

    or

    entity.Contains("attributename")

    Is that in plugin?

    If yes, can use post image and preimage (depends you want to update in pre event stage or post event stage.

    Because current entity context can be does not contain but preimage might have the value for preupdate and postimage for the post event.

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans