function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mw6mw6 

Validation rule between a picklist field and a look up field

I have a Picklist field on Case called Type with values 'Teacher Related, Policy Feedback, Curriculum Feedback' I have another field called Teacher_Name__c.  I need some help to write a validation rule so that if the user select the either 'Policy Feedback' or 'Curriculum Feedback' The teacher_name__c field should be made non editable and when the user choose 'Teacher Related' the Teacher_Name__c should be allowed to choose the teacher name.
Best Answer chosen by mw6
LBKLBK
If you are looking for a validation error message, when the user fills Teacher_Name__c when 'Policy Feedback' or 'Curriculum Feedback' is chosen, or vice versa, you can use the validation rule below.
OR(
AND(
ISPICKVAL(Type , "Teacher Related"),
ISBLANK(Teacher_Name__c)
),
AND(
OR(
ISPICKVAL(Type , "Policy Feedback"),
ISPICKVAL(Type , "Curriculum Feedback")
),
NOT(ISBLANK(Teacher_Name__c))
)
)

However, if you want UI level control to disable / enable Teacher_Name__c field based on the Type selection, you need to use a VF page with javascript.

Hope this helps.

All Answers

LBKLBK
If you are looking for a validation error message, when the user fills Teacher_Name__c when 'Policy Feedback' or 'Curriculum Feedback' is chosen, or vice versa, you can use the validation rule below.
OR(
AND(
ISPICKVAL(Type , "Teacher Related"),
ISBLANK(Teacher_Name__c)
),
AND(
OR(
ISPICKVAL(Type , "Policy Feedback"),
ISPICKVAL(Type , "Curriculum Feedback")
),
NOT(ISBLANK(Teacher_Name__c))
)
)

However, if you want UI level control to disable / enable Teacher_Name__c field based on the Type selection, you need to use a VF page with javascript.

Hope this helps.
This was selected as the best answer
Shivdeep KumarShivdeep Kumar
Hi,
Please take a look on below rule, it will help you.

AND(NOT(ISPICKVAL(Type, 'Teacher Related')), ISCHANGED( Teacher_Name__c))

Thanks
Shivdeep
Arvind KumarArvind Kumar
Hi,

You can use above answer. It will help you

Thanks
Deepak Maheshwari 7Deepak Maheshwari 7

We cannot make lookup field non-editable through validation rule but we can restrict the user to change Teacher name when 'Policy Feedback' or 'Curriculum Feedback' is selected.

(ISCHANGED(teacher_name__c ) && (ISPICKVAL(Type,"Policy Feedback") || ISPICKVAL(Type,"Curriculum Feedback")))
||
(ISNEW() && (ISPICKVAL(Type,"Policy Feedback") || ISPICKVAL(Type,"Curriculum Feedback")) && NOT(ISBLANK(teacher_name__c )))

mw6mw6
Hi Guys, Thank you for all your help, I used the rule from, LBK and it works.