Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

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

Posted on by Microsoft Employee

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
    ARIFNIIT 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
    ashlega 34,475 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
    Preeti Sharma 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
    Community Member Microsoft Employee 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans