Filter Dropdown by current user

Forums SPJS-Lookup Filter Dropdown by current user

Viewing 1 reply thread
  • Author
    Posts
    • #8359
      jstadick
      Participant

      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:

      Detail:
      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.

      spjs.lookup.init({
      	"fieldToConvertToDropdown":["Facility"],	
      	"listName":"UserAccess",
      	"listBaseUrl":"/sites/Root/Evergreen/crm",
      	"optTextFieldInternalName":"FacilityID",
      	"sortFieldName":"FacilityID",
      	"filterObj":{
      		"on":true,
      		"folder":"", // Leave empty to search in all folders
      		"CAML":"<Where><Eq><FieldRef Name='User' /><Value Type='Integer'><UserID /></Value></Eq></Where>",
      		"fin":"",
      		"isLookup":false,
      		"operator":"Eq",
      		"filterVal":""
      	},
      	"dropDownDefaultvalue":"",
      	"addYouOwnValue":{
      		"on":false,
      		"linkText":"Write your own value"
      	},
      	"addToExternalList":{
      		"on":false,
      		"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"
      	},
      	"debug":false
      });
      • This topic was modified 8 years, 6 months ago by Alexander Bautz. Reason: Wrapped the snippet in code tags
    • #8361
      Alexander Bautz
      Keymaster

      Thanks for taking the time to post it.

      Alexander

Viewing 1 reply thread
  • You must be logged in to reply to this topic.