0

I have created a validation rule whenever the picklist Field (status) is N/A I have to make another fields as not editable based on the picklist values .

Below is my validation rule :

AND(
ISPICKVAL( status__c,'N/A'),
ISCHANGED( NHPMS__Re_Admit__c ),
ISCHANGED( NHPMS__Discharge_Date__c ),
ISCHANGED( Next_Appointment__c )

)

I am able to change my Next appointment (pickList Field) and discharge date (Date Field)

Before Validation Rule Before Validation Rule

After Validation Rule After Validation Rule

3

Your current validation rule says the following

Block the user if the all of the following is true:

  1. Status__c = 'N/A'
  2. NHPMS__Re_Admit__c IS CHANGED
  3. NHPMS__Discharge_Date__c IS CHANGED
  4. Next_Appointment__c IS CHANGED

In your screenshot, only #1, #3, and #4 are true. You are not changing NHPMS__Re_Admit__c so the validation rule does not block you.

Based on your requirement, it sounds like you either:

  • Do not care if NHPMS__Re_Admit__c changes, in which case just remove it

or

  • Actually just want to fire if any of those fields change (not all of them together).

For that second scenario, you should leverage OR to denote that any of those fields changing meets criteria

AND(
    ISPICKVAL( status__c,'N/A'),
    OR(
        ISCHANGED( NHPMS__Re_Admit__c ),
        ISCHANGED( NHPMS__Discharge_Date__c ),
        ISCHANGED( Next_Appointment__c )
    )
)

The above will now block the user if the following is true:

  1. Status__c = 'N/A'
  2. Any single one of the 3 fields is changing
1
  • Thanks it's working as expected now i was using the and function as well but it was not working i used the below it didn't work your solution worked fine Thanks for the help AND( ISPICKVAL( status__c,'N/A'), AND( ISCHANGED( NHPMS__Re_Admit__c ), ISCHANGED( NHPMS__Discharge_Date__c ), ISCHANGED( Next_Appointment__c ) ) )
    – vijay
    Jul 30 at 15:14
2

The formula of a Validation Rule doesn't tell us when data is valid, it tells us when data is invalid.

So right now, you're saying that if Status = 'N/A' AND all of those fields are changing, that's invalid.

What you've described is that you want the Validation Rule to complain if any of those fields are changed. Thus, you want to use OR() for the ISCHANGED() part.

You still need that outermost AND() though. Put in the language of logic, invalid data is when Status = 'N/A' and (field1 is changed OR field2 is changed OR field3 is changed).

You should keep in mind that Validation Rules are generally not a great tool to allow some fields to be changed and require that others remain the same. It should work fine in this situation, but using recordtypes and page layouts is a superior approach.

2
  • 1
    +1 on the note about superior approach and considering the UX experience. Your suggestion or dynamic forms as suggested in their previous question (if possible) would be better options. Jul 30 at 15:01
  • so from the Dynamic forms we can make the field as Read only instead of adding as validation rules which would better suit my requirement i have to make the Fields as read only when the Picklist Field Value is changed.
    – vijay
    Jul 30 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.