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
sfdc-Lsfdc-L 

Need validaution rule for below scenario?

Hi all, i have picklist month field wich contains numeric values and year also i have picklist field.Lets say this year when you enter month i.e. Nov or Dec and year i.e. 2012 then it should not allow.So it should allow only month i.e Oct and year i.e.2012 (i.e.Current year of the previous month). Fields:month__c and Year__c Pls provide the example and let me know asap Thanks!
sourav046sourav046

Somewhat complex to achieve but not impossible .

 

You better add a Date picklist along with Month and year .

 

Then Add a formula field(suppose X) which concatenates Year ,month and date according to picklists .You may hide  this field from page layout.

 

Now use DATEVALUE(X) function to find the date  and compare that with TODAY() .

 

Try this and let me know if it working or not.

Madhan Raja MMadhan Raja M

Can you post the format how the Month and Year are stored in Picklist?

 

Madhan Raja M

larrmill59larrmill59

A better solution might be to just have a date field that they fill in. Then a validation rule that makes sure that date is last month. The formula could be 

 

OR ( 
YEAR( Attended_Date__c ) <> YEAR ( TODAY() ), 
MONTH( Attended_Date__c ) <> MONTH ( TODAY() ) - 1 
)

 

Then if you want the month and year fields to be pulled out for some other purpose, create formula fields for that like below.

 

MONTH( DATEVALUE(Attended_Date__c) ) 

 

YEAR( DATEVALUE(Attended_Date__c) )