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
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
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
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.
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.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156