Home › Forums › vLooup for SharePoint › Restrict "Add new item" to specific User Groups
- This topic has 4 replies, 2 voices, and was last updated 9 years ago by David S Kaimann.
-
AuthorPosts
-
-
October 28, 2015 at 12:57 #9075
Alex,
Is there any way (through Custom JavaScript) to only show the “Add new item” section of vLookup Fields to a specific User Group (or Groups)? I’d like to be able to do this in both ListView and the forms (Edit/Disp/New).
Thanks!
-
November 2, 2015 at 21:03 #9155
In forms you can use a rule to hide the “newItemWrap_vLookupFIELDINTERNALNAME” – replace FIELDINTERNALNAME with your fields name.
In list view you must write some custom code to get the groups for the user to determine whether or not to hide the button. Which version for SharePoint are you using?
Alexander
-
November 2, 2015 at 22:01 #9170
Thank you so much! I’m using 2010 right now, but we’ll be migrating to 2013 within the next few months. If you’re able to provide both options, it would be awesome!
Thanks!
-
November 4, 2015 at 19:51 #9187
This code should work in both SP2010 and SP2013. Add it to a CEWP in the view. You must change the fieldname “vLookupTasks” and add the name or id of your group in the code below. This code inserts a style tag to ensure all buttons are hidden correctly even if the vLookup is loaded after the script is loaded.
<script type="text/javascript" src="/SPJS/DFFS/plugins/SPJS-utility.js"></script> <script type="text/javascript"> var currentUserInfo = spjs.utility.userInfo(_spPageContextInfo.userId); var currentUserGroups = getGroupCollectionFromUser(currentUserInfo.Name); // check membership if(currentUserGroups["THE NAME OR ID OF YOUR GROUP"] === undefined){ var b = []; b.push("<style type='text/css'>"); b.push(".vLookupViewBtn_vLookupTasks{display:none;}"); b.push(".vLookupEditBtn_vLookupTasks{display:none;}"); b.push("</style>"); jQuery("body").append(b.join("")); } function getGroupCollectionFromUser(userLoginName){ var result = {}, id, name; spjs_wrapSoapRequest(L_Menu_BaseUrl + '/_vti_bin/usergroup.asmx', 'http://schemas.microsoft.com/sharepoint/soap/directory/GetGroupCollectionFromUser', '<GetGroupCollectionFromUser xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/"><userLoginName>' + userLoginName + '</userLoginName></GetGroupCollectionFromUser>', function(data){ jQuery('Group', data).each(function(idx, itemData){ id = jQuery(itemData).attr('ID'); name = jQuery(itemData).attr('Name'); result[id] = true; result[name] = true; }); }); return result; } </script>
Alexander
-
November 5, 2015 at 22:33 #9199
Perfect! Thank you!!!
-
-
AuthorPosts
- You must be logged in to reply to this topic.