Search code examples
sharepoint-2010sharepoint-designer

Hide/Show Form Field (Row) Based on Group


I am trying to see if within the new/edit form, I can restrict what certain people see based on what user/membership group they are in? I have read that you can use XSLT and achieve something similar by using: <xsl:if test="ddwrt:IfHasRights(#)"></xsl:if>. The issue is that we have multiple groups that may have similar privileges, but want to restrict to only a certain number of those groups.

Mainly, I am trying to see if there was a way to write something similar to: <xsl:if test="ddwrt:GroupName('My Group Name')"></xsl:if> OR <xsl:if test="GroupName = 'My Group Name'"></xsl:if>?

Thanks in advance...


Solution

  • <script type="text/javascript" src="http://code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.js"></script>
    
    <script type="text/javascript">
        $(document).ready(function() {
         $().SPServices({
          operation: "GetGroupCollectionFromUser",
          userLoginName: $().SPServices.SPGetCurrentUser(),
          async: false,
          webURL:"http://sp/",
          completefunc: function(xData, Status) {
            console.log(xData.responseXML);
            if ($(xData.responseXML).find("Group[Name='Designers']").length == 1)
             {
    
                   $("input[title=Title]").parent().parent().parent().hide(); 
              }  
            }
         });
        });
    </script>