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
adimoshuadimoshu 

How to make a text field required when a specified value is selected from a picklist?

I have a picklist with some values and a text field. When the "Other" value from the picklist is selected, i would like the text field to be required. Can somebody please help me ?

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Kent ManningKent Manning

About the only way to do this is to use a validation rule.  You would need something like:

 

ISPICKVAL(yourpicklist_field__c, "Other" ) && (textBoxField = " " )

 

This equation needs to evaluate to TRUE when someone tries to save the record, so you might need to play with the syntax to make the right conditions work. 

 

Hope that gets you started.

 

 

 

 

All Answers

Kent ManningKent Manning

About the only way to do this is to use a validation rule.  You would need something like:

 

ISPICKVAL(yourpicklist_field__c, "Other" ) && (textBoxField = " " )

 

This equation needs to evaluate to TRUE when someone tries to save the record, so you might need to play with the syntax to make the right conditions work. 

 

Hope that gets you started.

 

 

 

 

This was selected as the best answer
adimoshuadimoshu
thanks. it worked ok.
nickfs92840nickfs92840

Help! :)

 

I used your formul and checked the syntax and there were no errors. However, my form doesn't populate an error if the text field is left blank, please help!

 

ISPICKVAL(Request__c, "Fee Schedule Build" ) && (of_Medicare__c = "" )

 

 

Steve :-/Steve :-/

Try using something like this

 

 

AND( ISPICKVAL(Request__c, "Fee Schedule Build"), LEN( of_Medicare__c) < 1)

 

 

 

nickfs92840nickfs92840

Thanks for the quick response!

 

Still, does not populate an error code if the text field is left blank.

 

Please help 

Steve :-/Steve :-/

I'm not sure I understand.  Are you talking about creating an error message on the Validation Formula?  or are you trying to create a Formula Field that is populated with an Error Code if certain conditions are met? 

 

Can you post a screen shot of the Admin Setup page that you are trying to do this? 

Message Edited by Stevemo on 10-07-2009 03:43 PM
nickfs92840nickfs92840

If the text field "% of Medicare" is left blank when a user selects "Fee Schedule Build" from the picklist, an error code should be generated "Error: You must enter a value"

 

As you see from the other error codes populating, the one I'm trying to create is not generating this error code.

 

So the idea is to select "Fee Schedule Build" from the Request Type, and when doing so, when a user tries to select Save and the "% of Medicare" text field is blank, it should generate an error message.

 

Does this help?

 

Thank you... 

 

nickfs92840nickfs92840

Stevemo!

 

It worked! It had to do with the current validation rules I had in place.

 

thank you so much! 

 

 

Steve :-/Steve :-/
Thanks Nick, that helps a little, but what I was really looking for was a screenshot of the Field Validation Setup page where you are entering your validation formula.  I think that's where you have to make your changes.
nickfs92840nickfs92840

sure, check this out: 

 

 

nickfs92840nickfs92840

Stevemo, I have another issue, the Carrier_Local_Number__c is a picklist value and I get this error: Error: Field Carrier_Local_Number__c is a picklist field. Picklist fields are only supported in certain functions.

 

Here is the current formula that I have:

AND( ISPICKVAL(Request__c, "Fee Schedule Build" ), LEN( Carrier_Local_Number__c) < 1) 

 

Please help!  

Message Edited by nickfs92840 on 10-09-2009 11:59 AM
Steve :-/Steve :-/

Hi Nick, try changing it to something like

 

 

AND( ISPICKVAL(Request__c, "Fee Schedule Build" ), ISPICKVAL(Carrier_Local_Number__c, "" ))

 

 

 

nickfs92840nickfs92840
Stevemo! You saved the day once again! Thank you very much! :manvery-happy:
Steve :-/Steve :-/

No problem, that's why they pay me the BIG Bucks!  :smileywink:

 okay, actually it's more like the Big Pesos...

nickfs92840nickfs92840

Ok, I'm jealous lol

 

I have another issue but don't know if I should post here.

 

The validation rule is: Desired_Completion_Date__c - TODAY() < 5

 

What this validation rule does is when a user enters a date, they must enter a date 5 days from today. It works perfectly, however, when our analysts go into this form a few days later to update another field, the Desired Completion Date field asks for a new 5+ date.

 

Is there a way that the validation rule stays in place when originally inputted and when an analysts goes back in to update a field that the date field does not ask for a new 5+ date?

 

Here are some screen shots for your reference:

 

 

 

 

Steve :-/Steve :-/

If you want to do this for new records when they are first created then you can use this formula, otherwise you might have to add a few more lines of code if you need something a little more flexible.

 

Desired_Completion_Date__c - DATEVALUE(CreatedDate) < 5

 

 

nickfs92840nickfs92840

I tested the formula, however, if I enter today's date, it does not give me an error to enter a date 5+ days from now. 

 

So, for example, today is 10/13/09, this field should prompt me to enter a date of 10/18/09 and beyond.

 

However, lets say on 10/16/09, I go back to edit the form to update another field, the date field should not prompt me to

enter a date 5+ days from 10/16/09, it should keep the 10/13/09 date intact when I save the form. 

 

I hope this makes sense. Thank you!

Steve :-/Steve :-/

Hi Nick,

 

Could you post the formula that you are using?  When I tried mine it prevented me from creating a new record with a Delivery Date within 5 days, but allowed me to make edits to other fields after save without any prompts to update the Delivery Date (which is what I thought you wanted).

Message Edited by Stevemo on 10-13-2009 11:59 PM
nickfs92840nickfs92840

it was this formula: Desired_Completion_Date__c - DATEVALUE(CreatedDate) < 5

 

I take it back, it does work!!!!

 

Now, I have another add on to this and will post on a new post request.  

 

Your the man!! 

Message Edited by nickfs92840 on 10-14-2009 07:46 AM
nickfs92840nickfs92840

Ok, now that this formula works: Desired_Completion_Date__c - DATEVALUE(CreatedDate) < 5

 

How can you formulate it for "working days"?

 

For example, if the date is entered on a Thursday, the user should be prompted to enter the date that is 5 working days from Thursday, so the field should allow the user to enter it the following Wednesday. Anything before the Wednesday is less that 5 working days. 

 

Is it possible to omit Saturday and Sunday to create such a formula?

 

Thanks in advance!!!  

 

Steve :-/Steve :-/
No problem, wait'll you get my bill... :smileywink:
Steve :-/Steve :-/

Ouch...  okay, I'm officially outta my league now.  

 

However someone recently posted a Work Days formula on here within the last month or so.  I would do a search on Work Day  or Weekend Formula Validation (it should turn up).

 

 

Steve :-/Steve :-/

Okay, this is just the vanilla out of the box code, but this is what you need to do

 

 

 

Purpose: Calculate the number of days between two dates while excluding weekends or excluding weekdays. Formulas provided: 1.Weekday Count Formula 2.Weekend Days Count Formula Steps to create: 1.Create a formula field that returns a number. 2.Paste in one of the two formulas. 3.Replace StartDate__c and EndDate__c with your custom field values. 4.If using Date/Time fields ◦Replace with DATEVALUE(YourCustomDateTime__c) instead. Assumptions/Limitations/Background: •Weekdays are defined as Mon-Fri and weekends as Sat & Sun •Holidays are not addressed •June 6, 1985 is a long distant Monday used as a reference point •The result will include BOTH the START and END dates. ◦Mon-Sun is counted as 5 Weekdays and 2 Weekend Days. ◦Mon-Fri is NOT (Fri subtract Mon) = 4 Elapsed Days. ◦Sat-Sun is NOT (Sun subtract Sat) = 1 Elapsed Day. •If you use another Formula field as the start or end dates you MAY hit a compilation limit. ◦Workaround - Use workflow rules to save the output of the formula fields into a regular date field. •Be sure to TEST the formulas FIRST. Weekday Count Formula: CASE(MOD( StartDate__c - DATE(1985,6,24),7), 0 , CASE( MOD( EndDate__c - StartDate__c ,7),1,2,2,3,3,4,4,5,5,5,6,5,1), 1 , CASE( MOD( EndDate__c - StartDate__c ,7),1,2,2,3,3,4,4,4,5,4,6,5,1), 2 , CASE( MOD( EndDate__c - StartDate__c ,7),1,2,2,3,3,3,4,3,5,4,6,5,1), 3 , CASE( MOD( EndDate__c - StartDate__c ,7),1,2,2,2,3,2,4,3,5,4,6,5,1), 4 , CASE( MOD( EndDate__c - StartDate__c ,7),1,1,2,1,3,2,4,3,5,4,6,5,1), 5 , CASE( MOD( EndDate__c - StartDate__c ,7),1,0,2,1,3,2,4,3,5,4,6,5,0), 6 , CASE( MOD( EndDate__c - StartDate__c ,7),1,1,2,2,3,3,4,4,5,5,6,5,0), 999) + (FLOOR(( EndDate__c - StartDate__c )/7)*5) Weekend Days Count Formula: CASE(MOD( StartDate__c - DATE(1985,6,24),7), 0 , CASE( MOD( EndDate__c - StartDate__c, 7),1,0,2,0,3,0,4,0,5,1,6,2,0), 1 , CASE( MOD( EndDate__c - StartDate__c, 7),0,0,1,0,2,0,3,0,4,0,5,2,2), 2 , CASE( MOD( EndDate__c - StartDate__c, 7),0,0,1,0,2,0,3,1,2), 3 , CASE( MOD( EndDate__c - StartDate__c, 7),0,0,1,0,2,1,2), 4 , CASE( MOD( EndDate__c - StartDate__c, 7),0,0,1,1,2), 5 , CASE( MOD( EndDate__c - StartDate__c, 7),0,1,2), 6 , CASE( MOD( EndDate__c - StartDate__c, 7),6,2,1), 999) + (FLOOR(( EndDate__c - StartDate__c )/7)*2)