Validation working differently in table create and table update modes

Validation of user input works perfectly well in update mode but not in create (add) mode.  The reason being that the data is correct when I am updating a table but is not correct when I am adding to a table.

I am using the following validation condition:

PatientDetailForm.Record.ReferredBy.Label = "Doctor" and PatientDetailForm.Record.PatientDetails.Doctor = NullIdentifier() and PatientDetailForm.Record.PatientDetails.DoctorsName = ""

Explanation

A user (patient) fills out a form, wherein he/she selects who referred him/her.   If the user select "Doctor" they must either select a doctor from the drop-down list or enter the name of their doctor. If both fields are blank, it is an error condition.

Problem

When I am adding a record the ReferredBy.Label = "".  When I am updating a record, the ReferredBy.Label = "Doctor".

In the former case the error is bypassed and in the latter case the error is trapped.  I don't understand why it is not finding the value "Doctor" in the first case.

This is a traditional web application.

Screenshot

Hello Leon Holmes,

I cannot say where exactly your code is breaking but I can surely say, your validation condition is not proper. First it is not a good practice to hard code conditions, instead use static entity's label. I'm assuming you have a static entity for ReferedBy(if not, kindly create it), so your first condition should be,

PatientDetailForm.Record.ReferredBy.Label = Entities.ReferredBy.Doctor

Kindly post your logic flow snaps for better understanding of your requirement.


Thanks,

Sanjay

Sanjay Kumar Sahu wrote:

Hello Leon Holmes,

I cannot say where exactly your code is breaking but I can surely say, your validation condition is not proper. First it is not a good practice to hard code conditions, instead use static entity's label. I'm assuming you have a static entity for ReferedBy(if not, kindly create it), so your first condition should be,

PatientDetailForm.Record.ReferredBy.Label = Entities.ReferredBy.Doctor

Kindly post your logic flow snaps for better understanding of your requirement.


Thanks,

Sanjay

 Agree with your suggestion, just correcting the condition you have suggested above, it should be validated by Identifier not by the label.

PatientDetailForm.Record.ReferredBy.Id = Entities.ReferredBy.Doctor

Thanks,

Sachin

 

Solution

Hi Leon,

Let me start by saying that Sanjay and Sachin's remarks are valid, you should always check the Ids of static entities, never their labels. Unfortunately I believe they missed the real issue here. 

Before I explain the problem, let me first state what are my assumptions, based on what you describe (the names might be off, as you don't give full details, but hopefully I got the gist of it):

  • entity Doctor
  • default static entity ReferredBy
  • entity PatientDetails, with at least the following attributes:
    • Doctor reference attribute to a Doctor entity record;
    • ReferredBy reference attribute to a ReferredBy static entity record;
    • DoctorsName Text attribute (empty string if Doctor <> NullIdentifier())

In your preparation you have an Aggregate that fetches the PatientDetails information and this aggregate is joining the PatientDetails entity with (at least) the ReferredBy static entity (using PatientDetails.ReferredBy = ReferredBy.Id as Join condition).

This means that when you:

  • read your record from the database (so, when you are editing) all entity records of the Aggregate will have values so you could use your condition.
  • create a new record, your Aggregate will be empty, and so will all its entity records (including the ReferredBy record), which means your PatientDetailForm.Record.ReferredBy.Label = "Doctor" condition will fail.

On your form, your inputs are all mapping to attributes of PatientDetails, namely your dropdown for Referred By is bound to PatientDetailForm.Record.PatientDetails.ReferredBy and your dropdown for Doctor Search is bound to PatientDetailForm.Record.PatientDetails.Doctor, which means all your conditions should be based on the record you are allowing the user to fill in (so always validating attributes from PatientDetails only).

Given this information, your error condition would be something like:

PatientDetailForm.Record.PatientDetails.ReferredBy = Entities.ReferredBy.Doctor
and PatientDetailForm.Record.PatientDetails.Doctor = NullIdentifier()
and PatientDetailForm.Record.PatientDetails.DoctorsName = ""

I would read this as: the user has chosen a Doctor as the referrer and has not selected any doctor from the dropdown nor provided a doctor's name. If this condition is true, then you have a validation error. 

Hope the explanation wasn't too long or confusing and I managed to help you...

Solution

Thank you Jorge.  Your explanation is perfectly clear. It solved my problem and helped me better understand the dynamics better.

Thank you to everyone for their input.