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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Populate LookUp Field

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    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

  • happysingh0009 Profile Picture
    160 on at

    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
    Bipin D365 Profile Picture
    28,983 Moderator on at

    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
    160 on at

    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
    28,983 Moderator on at

    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

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 73 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans