Home › Forums › SPJS-Lookup › Filter Dropdown by current user
- This topic has 1 reply, 2 voices, and was last updated 9 years, 2 months ago by Alexander Bautz.
-
AuthorPosts
-
-
September 5, 2015 at 02:33 #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:
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 9 years, 2 months ago by Alexander Bautz. Reason: Wrapped the snippet in code tags
-
September 5, 2015 at 08:18 #8361
Thanks for taking the time to post it.
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.