Web Connection
nupdatemode setting between adding new record or editing record
Gravatar is a globally recognized avatar based on your email address. nupdatemode setting between adding new record or editing record
  Doug
  All
  Apr 30, 2019 @ 06:17pm

I have a method to manage records, which have a unique code. I call the method with no parameters. When the method receives no parameter, the subject .nupdatemode is set correctly to 2 (new record) and the screen present properly. However, when saving the "new record" and the object is recreated, the nupdatemode is reset to 1 (edit record) and my duplicate code check in the validate method of the business class treats it as an update rather than a duplicate.

When should I be setting the nupdatemode so that my business object validate method knows it is an edit or an add?

Thanks, Doug

Gravatar is a globally recognized avatar based on your email address. re: nupdatemode setting between adding new record or editing record
  Rick Strahl
  Doug
  Apr 30, 2019 @ 08:17pm

In most cases this should be automatic. If you use New() or Load() to load or create an entity the value will be set appropriately. When you call Save() and it succeeds that too should set the value automatically to edit. Any time you save successfully the record is considered 'not new'.

If you need to track the state of the object outside of these very simple situations you have to track it yourself. You can always use the mode as a base and then expand on that when you know the state is changed in an unexpected way.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: nupdatemode setting between adding new record or editing record
  Doug
  Doug
  May 1, 2019 @ 09:05am

But when a duplicate code is entered in the "new" form (after calling method with no parameter), the duplicate code is found (because it already exist) during the Load method (when attempting to save the "new" record) and sets the nupdatemode to 1 (edit). Because it is in edit mode, my validate() method doesn't know it is an attempt to add the record and does not check for a duplicate. It just saves it as an update. When it should reject for duplicate code (pk).

Gravatar is a globally recognized avatar based on your email address. re: nupdatemode setting between adding new record or editing record
  Rick Strahl
  Doug
  May 1, 2019 @ 04:29pm

I don't know what you mean by "New Form" - that's a different level of abstraction. If you're feeding values into the business layer that can have dupes you have to verfify those before you save (or potentially before you load if that matters).

If a user enters a new form and enters data for an existing ID there, then you you have to decide how to handle that - there's no way to automatically resolve that in the generic business layer. Your application has to decide whether to:

  • Load the data and then overwrite
  • Create a new record with new ID
  • Create a duplicate ID record (valid in some cases)

Duplicate checking generally can be done in the Validate() override of your business object.

+++ Rick ---

© 1996-2024