Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Populate LookUp Field

Posted on by 160

hi 

i have three tables(Given Below). i want to write a plugin on CREATE Message on Membership Table. when i create a record in "MEMBERSHIP" table, a record in "MEMBERSDETAILS" table will automatically created. can anyone please give a hint/idea, how i can do this

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Populate LookUp Field

    Hi,

    You are setting Empty guid for contact lookup and that is why you get that error

    Add check condition as below before you map the field.

    if(contactId!=Guid.Empty)

    Map your look field

    Thanks,

    Bipin

  • happysingh0009 Profile Picture
    happysingh0009 160 on at
    RE: Populate LookUp Field

    Exception Message: ReferencingEntity=tpamm_membershipmembers has attribute tpamm_members value=Guid.Empty for relationship=tpamm_MembershipMembers_Members_Contact, relationship.ReferencedEntity=contact, relationship.ReferencedAttribute.PlatformName=contactid

    I got this error this ur code.

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Populate LookUp Field

    Hi,

    Try below code -

    Entity membershipDetails=new Entity("new_membershipdetails");

    membershipDetails["membershipid"]=new EntityReference("new_membership", membershipId);

    membershipDetails["contactid"]=new EntityReference("contact", contactid);

    service.Create(membershipDetails);

    membershipId -> You will get it from Target Entity

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • happysingh0009 Profile Picture
    happysingh0009 160 on at
    RE: Populate LookUp Field

    Hi Sir

    Thank You for Reply :)

    i already read the contact table (it also have lookup inside membership table). But face problems in creating an object for member table.

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: Populate LookUp Field

    the plugin needs to run in POST operation (usually synchronous) otherwise you will not have the ID of the membership you just created.

    Inside the plugin you read the Contact (I suppose there is a lookup pointing to Contact inside Membership) and after you create a new MemberDetails record filling the two lookups (one pointing to Membership with the ID you got and the other to Contact)

    Maybe this can be done also with a classic workflow but I usually write plugins in this scenario.

    hope it helps

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans