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 2 years, 11 months ago.

  • 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 2 years, 11 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

You must be logged in to reply to this topic.