Answered by:
Validation rule to check for duplicate entity only fires when saving, not when adding the entity from the screen

Question
-
I have a Businesses table, a Categories table a Listing table, and a ListingsTypes table, where the idea is that businesses can be listed in categories, and listings can be of various types. I would like to write a validation rule that ensures that each business can only have one listing of any type in each category.
I added code for the Listings_Validate method, and checked if there was already a listing in there. If so, I add an entity error.
This works fine, except that the error is only flagged up to the user when they try to save the data. At the moment, they can add duplicates, and won't get notified of the problem until they click the Save button. I would like it flagged as soon as the user tries to add the listing, ie from the pop-up window where they add an entity, or from the grid if they edit an existing listing in the grid.
In this video, she does something similar, but is writing code against the product property of the OrderDetail entity. I can't do that as my Business entity has a Listings collection, not a single entity, and it won't allow me to write a validation rule against that. Also, this wouldn't make sense, as the Category entity also has a Listings collection, so I would have to write the same code twice. It seems logical to put the code on the Listing entity, but I want it run immediately, not wait until the user tries to save the data.
Any idea how I can do this?Thanks
If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/Monday, August 29, 2011 4:35 PM
Answers
-
You may try this approach.
Cheers
Cliff
- Proposed as answer by Cliff_McManus Sunday, October 16, 2011 5:36 PM
- Marked as answer by Justin AndersonMicrosoft employee, Moderator Monday, April 2, 2012 7:25 AM
Friday, September 30, 2011 12:21 PM
All replies
-
Please provide a screen shot of screen that shows how this looks.Monday, August 29, 2011 7:13 PM
-
You may try this approach.
Cheers
Cliff
- Proposed as answer by Cliff_McManus Sunday, October 16, 2011 5:36 PM
- Marked as answer by Justin AndersonMicrosoft employee, Moderator Monday, April 2, 2012 7:25 AM
Friday, September 30, 2011 12:21 PM -
Hi Cliff, thanks for the reply. As it happens, the business rules for this part of the app have changed, so I don't need this now, but your approach looks good, and has been noted for the future.
If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/Sunday, October 2, 2011 2:44 PM