Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

CRM 1 to 1 relationship

Posted on by Microsoft Employee

I need help on knowing how to create a relationship that prevents a contact from having more then 1 address

my issue is contacts can only have one address 

address is related to contacts

if one tries to add another address an error should appear

I know its possible how does one do this with workflows

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM 1 to 1 relationship

    I did a odata call via the onsave event to "expand into the relationship to address and I check the related record if a address already existed by checking for an existing id then I did a prevent default save

  • Suggested answer
    Ryan Maclean Profile Picture
    Ryan Maclean 3,070 on at
    RE: CRM 1 to 1 relationship

    Hi Lucky,

    I had a similar problem within my system, and I accomplished it as follows:

    1. I created a custom Address entity (there were a number of reasons that the OOTB Address entity was not suitable for our purposes).

    2. When an Account is created and the Address fields are filled in, this creates a new "Head Office" Address for the company.

    3. I added a subgrid to the Account form to allow multiple addresses to be created against an Account

    4. On the Contact form I created a Lookup to the Address entity called "Address Selector", which showed all of the Address records related to the Parent Account for the Contact

    5. On selection of the relevant Address in the Lookup I have a real-time workflow that populates the Address details on the Contact

    6. When the Address Selector field is populated there is a Business Rule that locks the address fields so they can't be edited.

    This isn't an ideal solution, but it should hopefully give you some food for thought

  • Clem Profile Picture
    Clem 2,541 on at
    RE: CRM 1 to 1 relationship

    Hello,

    You can check the following link : crmtipoftheday.com/.../create-a-11-relationship

    Clément

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: CRM 1 to 1 relationship

    Hi,

    You could create a register a plugin on update event in post operation to do the same.

    Try the following code.

    Entity contact= context.InputParameters["Target"] as Entity;
    
                if (contact!= null)
                {
                    if (context.MessageName.ToLower() == "update")
                    {
                        if (contact.LogicalName == "contact")
    
                        {
                            //Obtain the pre image
                            Entity preContact = (Entity)context.PreEntityImages["Image"];
    
                            //Obtain the post image
                            Entity postContact= (Entity)context.PostEntityImages["Image"];
    
                            //Obtaing the old company name
                            string preAddress = preContact.GetAttributeValue<string>("address1_composite");
    
                            //Obtaing the new company name
                            string postAddress = postContact.GetAttributeValue<string>("address1_composite");
    
                            if (preAddress != postAddress)
    
                            {
                                throw new InvalidPluginExecutionException("Address cannot be changed");
                            }
                        }
                    }
                }

    Refer the links below to know about pre and post images of the update event and how to register it using plugin registration tool.

    sumedha8.blogspot.in/.../sample-plug-in-compare-pre-and-post.html

    community.dynamics.com/.../utilising-pre-post-entity-images-in-a-dynamics-crm-plugin

    Hope this helps.

  • Michel Gueli Profile Picture
    Michel Gueli 982 on at
    RE: CRM 1 to 1 relationship

    Out of the box this is not possible. You can create a pre-validation plugin on the address entity to check if the contact already has an address.

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans