Dynamic Filter for Lookup field

Dynamic Filter for Lookup field

Hi all,
I have a dynamic Lookup field. Each record in the "Sites" form has an "AMUser", and the current user sees a filtered list based on this. The lookup is configured like this: 
  1.     must  have  Site1
  2.     (
  3.         displayname  =  "Site"
  4.         type  =  picklist
  5.         values  =  Sites[AMUser == zoho.loginuser].ID
  6.         displayformat = [ Site_name ]
  7.         sortorder  =  ascending
  8.         searchable  =  true
  9.         width  =  206px
  10.     )
However, I'd like to nest this in an If statement so that if the current user has not been allocated any Sites, they see the full list. Something along the lines of:
  1. CountList = Sites[AMUser == zoho.loginuser].count()
  2. IF Countlist = 0 THEN
  3. {
  4. values = Sites.ID
  5. }
  6. Else
  7. {
  8. values = Sites[AMUser == zoho.loginuser].ID
  9. }
I'm not sure how to code this in the Form Definition and keep getting 'null' errors. Can anyone point me in the right direction?