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
Annie LydonAnnie Lydon 

Using Validation Rules on Picklist to make Text Field Mandatory/Required

Hi all,

My mission statement:  Use picklist values to determine whether or not a text field should be mandatory/required

I tried the formula above as a validation rule:

IF(ISPICKVAL(Charities_Register_Status__c , "Registered"),LEN( Charities_Register_No__c )<1, Charities_Register_No__c =NULL)


where 'Charities_Register_Status' = Picklist
and 'Charities_Register_No' = Required Text Field

I only want the 'Charities_Register_No' to be Mandatory/Required if the 'Charities_Register_Status__c' selection = 'Registered'

Can anyone confirm if the validation rule I've used above is correct to achieve this?  I've tested it and no matter what the 'Charities_Register_Status__c' selection, the 'Charities_Register_No' is still required.

 
AbhishekAbhishek (Salesforce Developers) 
Hi Annie,

You can try the suggestion as mentioned in the below blog,

https://success.salesforce.com/answers?id=90630000000hqJsAAI

It might answer your query.

Thanks!
MoonpieMoonpie
Hi Annie,

You only need to return TRUE for the condition that you want to cause the error message to show (the validation to fail).  So you do not need an IF statement.

The IF statement looks at the first term and checks whether it is TRUE or FALSE
- if TRUE, it takes the second term as the value for this formula
- if FALSE, it takes the third term as the value for this formula

So your IF statement basically says,
"If the Charities Register Status field value is "Registered", then this validation rule is: FAIL if the length of the Charities Register # is less than 1.
[So far, so good...]

"BUT, if the Charities Register Status field value does NOT equal "Registered", then this validation rule is: FAIL if the length of the Charities Register # is NULL.

So you have effectively made this field always required!

As I originally stated: all you need is an operation that returns TRUE for the conditions in which you want to fail.  You do NOT have to include the conditions that are acceptable - by default those will be everything else.

Try this:
AND(
   ISPICKVAL(Charities_Register_Status__c , "Registered"),
   LEN(Charities_Register_No__c) < 1
)
That says, "If the Charities Register Status field value is "Registered", AND the length of the Charities Register # is less than 1, then FAIL".

Otherwise, it should allow anything else - including the # field being empty if the Status field is not "Registered".

Does that makes sense?

---
Or better yet, try this:
AND(
   ISPICKVAL(Charities_Register_Status__c , "Registered"),
   ISBLANK(Charities_Register_No__c)
)
MoonpieMoonpie
Hi Annie,

Did you try what I suggested?  If so, did it work?
Or did you do something else that worked?
Or do you still have the problem?

Please update.

Thanks!