-1

enter image description hereI am trying to create a validation rule on my Booking object so that the Booking can only be active if the Occupancy status on the Booking is either In House or Temporarily Vacated or Blocked out or Reserved.

The Active Booking field is a formula checkbox type with the formula

AND(check_in_date__cc <=TODAY().  Check_out_date__cc.>=TODAY()

My validation rule 'Verify Occupancy' (below) keeps getting errors.

Error: Incorrect number of parameters for function 'IF()'. Expected 3, received 1

Thanks if anyone can resolve.

IF(

AND(

Active_Booking__c = TRUE,

 
AND(

ISPICKVAL(Occupancy__c, 'In House'),

AND(

ISPICKVAL(Occupancy__c, 'Reserved'),

AND(

ISPICKVAL(Occupancy__c, 'Temporary check out/returning'),

AND(

ISPICKVAL(Occupancy__c, 'BLOCKED OUT'),

true, false))))))
3
  • You have terminated the AND & IF conditions incorrectly. It has to be IF(AND(Active_Booking__c = TRUE, AND(ISPICKVAL(Occupancy__c, 'In House'), AND(ISPICKVAL(Occupancy__c, 'Reserved'), AND(ISPICKVAL(Occupancy__c, 'Temporary check out/returning'), ISPICKVAL(Occupancy__c, 'BLOCKED OUT'))))),true, false). Read more about IF formula here. – arut Nov 2 '20 at 3:09
  • Thanks @arut. Both of these work in the sense that they do not return any error messages but when I test a booking and set the occupancy to Cancelled then the Active Booking checkbox remains true? – Wineswitch Nov 2 '20 at 6:12
  • Validation rules only verify if the data entered meets the specified requirements before the record can be saved. They don't update any existing field. You can read more about validation rules here. The value of Active Booking checkbox is determined by the formula you have defined on this field. So, you need to tweak this formula to achieve your requirement. – arut Nov 2 '20 at 7:38
0

The if condition in formula builder expect you to return for true condition and false condition. You have defined the condition but not returned any value for true/false condition. Instead you had written inside AND which is wrong in your case. Also, you can remove all the AND condition and keep one.

IF(
    AND(
            Active_Booking__c = TRUE,
            ISPICKVAL(Occupancy__c, 'In House'),
            ISPICKVAL(Occupancy__c, 'Reserved'),
            ISPICKVAL(Occupancy__c, 'Temporary check out/returning'),
            ISPICKVAL(Occupancy__c, 'BLOCKED OUT')
        ), 
    true, false
)
2
  • Thanks @sanket kumar. Both of the above work in the sense that they do not bring any error messages but when I test a booking and set the occupancy to Cancelled then the Active Booking checkbox remains true? – Wineswitch Nov 2 '20 at 6:11
  • you can eliminate the IF, true, false altogether as AND returns a Boolen – cropredy Nov 3 '20 at 4:47

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.