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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

how to update child records from the parent context using custom workflow?

(0) ShareShare
ReportReport
Posted on by

Hi guys,

i have a requirement i need to update child record from the parent context using custom workflow.

I used below code but throwing an error "given key was not present in the dictionary".

should i use any arguments to achieve this?

try
{
Entity entity = new Entity();
entity.LogicalName = "tj_country";
EntityReference child = (EntityReference)entity.Attributes["tj_child"];
Guid cid = child.Id;
Entity childentity = new Entity();
childentity.LogicalName = "tj_state";
childentity.Id = cid;
childentity.Attributes["tj_districts"] = new OptionSetValue(212200000);
service.Update(childentity);

}

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi,

    Instead of the childentity.Attributes ["tj_districts"] = new OptionSetValue (212200000) try to use childentity.Attributes.Add ("tj_districts", new OptionSetValue (212200000));

    Or you can remove the word Attributes something like this hildentity ["tj_districts"] = new OptionSetValue (212200000);

    Hope this helps

    Vlad

    http://dynamicalabs.com/

  • Suggested answer
    Preeti Sharma Profile Picture
    2,678 on at

    Hi,

    Please check if logical names of fields "tj_country","tj_child","tj_state" and ""tj_districts"" are same as defined in CRM.

    This error generally occurs when no field with specified logical name is found in CRM.

    Hope This Helps!

    Thanks

  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    Hi,

     when you are creating that entity in the code, it's just an in-memory object - not a record from the database.

     Hence, it does not have tj_child attribute until you set it..

     Instead, you have to use Retrieve to get that entity from the db.. Something like this:

     var entity = Service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet("tj_child");

  • Suggested answer
    ARIFNIIT Profile Picture
    1,391 on at

    Validate you entity fields logical name. "given key was not present in the dictionary" error occurs when no field with specified logical name is found in CRM for particular entity

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans