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

  • Suggested answer
    ARIFNIIT Profile Picture
    1,391 on at
    RE: how to update child records from the parent context using custom workflow?

    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

  • Suggested answer
    ashlega Profile Picture
    34,477 on at
    RE: how to update child records from the parent context using custom workflow?

    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
    Preeti Sharma Profile Picture
    2,678 on at
    RE: how to update child records from the parent context using custom workflow?

    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

  • Community Member Profile Picture
    on at
    RE: how to update child records from the parent context using custom workflow?

    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/

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans