Filter Dropdown by current user

Forums SPJS-Lookup Filter Dropdown by current user

This topic contains 1 reply, has 2 voices, and was last updated by  Alexander Bautz 3 years, 4 months ago.

  • Author
  • #8359


    In using the lookup function, I had the need to filter the dropdown by the current user. After the gracious help of Alexander, below was the solution.

    Hope it helps anyone else with a similar need.

    Problem: Need to display a list of facilities for the user to select from, but limit the list to only those they have access to.

    Solution: Use the SPJS-Lookup function and filter based on the current user:

    Field on the form being converted to the function: Facility
    I have a custom sharepoint list called UserAccess with two fields:
    Facility (Single Line Text)
    User (People Picker)

    We used a custom CAML statement to filter the list based on the current user.

    Below was the function call. Also, I was using this with DFFS tabs, so the code was placed in the Custom JS box in the Misc Tab of the DFFS setup. The real magic is the CAML query.

    		"folder":"", // Leave empty to search in all folders
    		"CAML":"<Where><Eq><FieldRef Name='User' /><Value Type='Integer'><UserID /></Value></Eq></Where>",
    		"linkText":"Write your own value"
    		"customFunction":null, // Function name as a string. If a function name is supplied, this will be used in stead of the default function. The function will be passed the argument object as a parameter.
    		"linkText":"Add new item",
    		"saveNewItemText":"Save new item"
    • This topic was modified 3 years, 4 months ago by  Alexander Bautz. Reason: Wrapped the snippet in code tags
  • #8361

    Alexander Bautz

    Thanks for taking the time to post it.


You must be logged in to reply to this topic.