Restrict "Add new item" to specific User Groups

Forums vLooup for SharePoint Restrict "Add new item" to specific User Groups

Viewing 4 reply threads
  • Author
    Posts
    • #9075
      David S Kaimann
      Participant

      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!

    • #9155
      Alexander Bautz
      Keymaster

      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

    • #9170
      David S Kaimann
      Participant

      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!

    • #9187
      Alexander Bautz
      Keymaster

      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

    • #9199
      David S Kaimann
      Participant

      Perfect! Thank you!!!

Viewing 4 reply threads
  • You must be logged in to reply to this topic.