1
votes

I have found a number of recommended ways in blogs looking to answer how to do this and have not successfully made any of them work using SharePoint MOSS 2007 and SharePoint Designer 2007.

I have already hidden the fields that I don't want any user to see within the site content type (those fields being set by a SharePoint Designer Workflow).

I'm trying to hide specific fields on the NewForm.aspx and EditForm.aspx based on whether the current user is in a Specific SharePoint group. My list has a site content type that I created and site columns.

When I look at the NewForm.aspx in Designer the design view gives me generic Field 1, 2, 3 and not my specific content types. If I create a new aspx page and insert SharePoint control > custom list form, then my fields show up. I'll take ways to edit in designer if you have them, but I need someone to check the solution below and help me figure out where I'm messing up.

Went with option indicating to use jquery (1.9.0.js) and SPServices (0.7.2.min.js).

  1. I uploaded both files to a document library on my site.

  2. I then created a CEWP on my NewForm.aspx page (not through designer but the front-end by appending "shared&ToolPaneView=2" to the url.

  3. Pasted the following code into the CEWP:

"

<script type="text/javascript" language="javascript" src="/Style%20Library/JavaScript%20Utilities/jquery.SPServices-0.7.2.min.js"></script>

<script language="javascript" type="text/javascript">

$(document).ready(function() {

  $().SPServices({

    operation: "GetGroupCollectionFromUser",
    userLoginName: $().SPServices.SPGetCurrentUser(),
    async: false,
       completefunc: function (xData, Status) {
       var xml = xData.responseXML.xml;
       if (xml.search('MyGroupName') != -1)

function hidefields() {

         var control = findacontrol("MyColumnName");
         control.parentnode.parentnode.style.display="none";
  }
     }
  });
});
</script>

When I click save in the 'Source Editor' dialogue box, it closes and on my main browser status I get a message 'Please wait while scripts are loaded..." and then nothing happens. I can click okay on the Modify Shared Web Part menu and the web part closes. Get same wait message...

Goal is that if current user is not part of MyGroupName then the field for MyColumnName will not be visible on the page. Not a developer but trying to play one in real life.

If you're still reading, Thanks!!!

2

2 Answers

0
votes

The script you have provided is not going to work. Just checking, did you include a <script /> declaration for jQuery as well as SPServices? Does the browser show any script errors occurring during page load? I've occasionally got a 404 because I didn't reference the script files correctly.

Also, if your xml.search('MyGroupName') succeeds, you declare a new function. I suspect you want call the function rather than just declare it. However jQuery provides some useful shorthands for the type of operation you're trying to perform. For example if "MyColumnName" is the id of a column you can do something like:

<script type="text/javascript" language="javascript" src="/Style%20Library/JavaScript%20Utilities/jquery.SPServices-0.7.2.min.js"></script>

<script language="javascript" type="text/javascript">

$(document).ready(function() {

  $().SPServices({

    operation: "GetGroupCollectionFromUser",
    userLoginName: $().SPServices.SPGetCurrentUser(),
    async: false,
    completefunc: function (xData, Status) {
      var xml = xData.responseXML.xml;
      if (xml.search('MyGroupName') != -1) {
        $("#MyColumnName").parent().parent().hide();
      }
    }
  });
});
</script>

If 'MyColumnName' isn't the id of the element you're trying to find there are alternative ways to match the element you want to hide. Have a look at jQuery.com, in particular jQuery selectors for alternatives.

0
votes

Use : if (xml.search('Group Name') == -1) { //Hide the controls }

See the complete implementation at: Hide SharePoint List Columns based on User Permissions