CRM 2011 KeyNotFoundException exception

后端 未结 4 1162
心在旅途
心在旅途 2021-01-22 08:00

I am new to CRM development. I have a Custom Entity \"customer\". This Entity has a Field called \"defaultcustomer\", which can be TRUE or FALSE. I am working on a Plug-In where

相关标签:
4条回答
  • 2021-01-22 08:40

    The error means that particular field is not present in the collection of properties. In CRM, only properties that have been set or updated are included.

    Try something like:

    foreach (Entity myCustomer in retrieved.Entities)
    {
        if (myCustomer.Attributes.ContainsKey("defaultcustomer"))
        {
            myCustomer["defaultcustomer"] = false;
        }
        else
        {
            myCustomer.Attributes.Add("defaultcustomer", false);
        }
        service.Update(myCustomer);
    }
    
    0 讨论(0)
  • 2021-01-22 08:55

    The solution posted by @glosrob seems fine. Are you still getting "The given key was not present in the dictionary"?

    Try to use ITracingService to get more information about the plugin execution flow.

    0 讨论(0)
  • 2021-01-22 09:03

    Have you double checked that the field really is called defaultcustomer?

    If it's a custom entity then it's likely the field begins with a prefix, for instance new_defaultcustomer. Make sure you are using the name of the field, not the display name.

    0 讨论(0)
  • 2021-01-22 09:05

    While Update all Crm fields are False accept that what you Update the field. For that you can use Pre/Post Images in Plugin. you will found that crm field key and update what you need.

    0 讨论(0)
提交回复
热议问题