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)

Error generated on saving a record

(0) ShareShare
ReportReport
Posted on by
I have a custom entity Programme which is associated with Account. When trying to add a new Programme I get Unhandled exception: Exception type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault] Message: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at
    RE: Error generated on saving a record

    Hi Julian,

    looks like you have a plugin code running on creation of "Programme" entity.

    and in that code a key "field/attribute" is being reference which is not there in the "target" or the retrieved collection.

    community.dynamics.com/.../the-given-key-was-not-present-in-the-dictionary-what-it-means-and-how-to-avoid-it  

  • Suggested answer
    Sreevalli Profile Picture
    3,256 on at
    RE: Error generated on saving a record

    Hi,

    Do you have account lookup field on the form and you are filling it before saving?

    Share more details on relationship type and any code behind on save/create.

  • Suggested answer
    gupta.ambar2009@gmail.com Profile Picture
    797 on at
    RE: Error generated on saving a record

    hello ,

    Please check contain ,before retrieve any attribute ,like below

    if(Entity.attribute.contains("Attribute"))

    {

     // then  fetch here

      myEnttiy["Attribute"] =Entity.getAttributevalue<type>("Attribute");

    }

  • Julian Richardson Profile Picture
    on at
    RE: Error generated on saving a record

    The error started yesterday midday. We are on v9.0

    It worked fine before then.

     I have a custom entity called Programme. Its accessed via a subgrid from the Account form

    P4.jpg

    It opens.

    1425.P2.jpg

    Selecting ADD NEW PROGRAMME it opens the New Programme form, adds the Account name and has a lookup for Programme type. On selecting Programme Name and trying to save the record I get the error message provided.

    1425.P3.jpg

     

    If I go direct to the Programme Module and do NEW, and the do a lookup on Account name and then do the lookup for the Programme name, the record then saves without a problem. When I then go back to my Account record the new programme does not appear in the subgrid view, it has to be added by finding it via ADD EXISTING PROGRAMME.

    P4.jpg

     

    The Project Name Skills  was added direct from the New Programme form and added using ADD EXISTING PROGRAMME, the other two were added correctly via the subgrid on the Account form (top screenshot)

     

    Just tried adding the same subgrid to the contact form and although it links to the Main contact rather than Account it works fine so it seems to be something relating to the association between Account and Programme ( Sorry I'm new to both the community and this level of fault diagnosis)

    As far as I know there are no plugins associated with the Programme entity I only built it a few weeks ago.

    Hope this helps.

  • Julian Richardson Profile Picture
    on at
    RE: Error generated on saving a record

    Hi Sreevalli.

    There is an Account lookup and it is filled automatically. The only other field required is Programme Name. This is another lookup.

    Thanks

  • Suggested answer
    Sreevalli Profile Picture
    3,256 on at
    RE: Error generated on saving a record

    Hi,

    line from above message, Selecting ADD NEW PROGRAMME it opens the New Programme form, adds the Account name and has a lookup for Programme type. On selecting Programme Name and trying to save the record I get the error message provided. Are you able to see the newly created record from view/advance find. if not then that means there is an asynchronous which is failing to save the record, but you could not able to see the error while saving.

    if this is the case then check for asynchronous workflows and plugins.

  • Julian Richardson Profile Picture
    on at
    RE: Error generated on saving a record

    Hi Sreevalli. It does not seem to be creating the Programme record.  However I have just created a copy of the Programme form, I removed the Account Look field from the form and it now saves correctly so although it does populate the Account name field correctly,the error does seem to be related to creating the link between the new record and the parent account via the Account lookup field. Does that make sense?

    regards.

  • Suggested answer
    Sreevalli Profile Picture
    3,256 on at
    RE: Error generated on saving a record

    Hi Julian,

    For me it sounds like linking issue, as you are able to save the record without account details, isn't it?

    How about creating programme after removing account lookup details, through sub grid, check it?

    What is the behaviour on account lookup update on programme form?

  • Julian Richardson Profile Picture
    on at
    RE: Error generated on saving a record

    Hi Sreevalli.

    Its not the field, I just created a new Account lookup field called 'New Account' field and using that also gives the same error message.

  • Suggested answer
    Dynamics365 Rocker Profile Picture
    7,755 on at
    RE: Error generated on saving a record

    You have to update your code.

    You have to add an if condition wherever you are using account.

    You code will look like below:

    if(entity.contains("accountid"))

    {

    var account=Entity.getAttributevalue<type>("accountid")

    }

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