How to restrict SharePoint WSS3 users to edit only fields that are in their dedicated views - sharepoint

I have a list with the fields: Title, Client, Project, Description.
There is a view for analysts with the fields visible: Title, Project, Description.
All is fine so far as the analysts work with their views and not with the lists. But when they need to modify the records clicking on Edit, they see and able to modify the 'Client' field too.
How to prevent 'Client' field to be available for editing by the group? is there a way in WSS or I need to look for 3rd party list components?

All fields have a set of properties that determine their visibility in forms, such as "ShowInNewForm", "ShowInEditForm", and "ShowInDisplayForm". There's also some for the file dialog, the list settings page, and a few other places, but that's getting past it. Short answer, yes, you can make the field not show up in the edit form with WSS without needing any 3rd party components.
If you need a field that cannot be seen in the Edit Form by anyone (that is, no one should be able to have it in their form), then you need to modify "ShowInEditForm" to be true. This can't be modified directly through the SharePoint UI, but it is extremely simple using the object model.
If you need certain people to edit it at some point through the SharePoint UI, then you'll instead have to create a custom edit form. That's a bit more complex, so I'll hold off on providing that instruction unless you state you need to go down that route (or someone else passes by this answer and requests it). Nevertheless, it is fully possible with WSS 3.0.
EDIT
If you know already know how to insert inline C# code into an ASPX page, you can perform this very simply using SharePoint Designer. First, follow the instructions from this article, especially make sure you don't delete the default list form web part. Now, in the custom list form you added, make it include every field which anyone will be capable of editing. The last step is to make the form hide those fields for certain people. Let's default them to Visible=false, and flip this switch if the user is allowed them. You can do this either by checking if the current user is part of specified groups, or by checking if the user has a certain permission level only held by people of those groups. You'll basically write some code like the following, I'll use checking for a specified group as the example.
using (SPWeb web = this.Web)
{
SPUser currUser = web.CurrentUser;
string[] listOfGroups = { "Group1Name", "Group2Name", "Group3Name" };
foreach (string groupName in listOfGroups)
{
if (currUser.Groups.Contains(groupName))
{
//Repeat this for each Control, refer to them by their ID. For example, this is for a control with the ID txtTitle.
txtTitle.Visible = true;
}
}
}
If you don't know inline code, you'll have to write a custom ASPX page with a code-behind. Copy EditForm.aspx into a new file - you should do this after setting up a Custom List Form as per the article. You could also build a new ASPX page from scratch, but make sure you include all of the necessary Content placeholders for SharePoint pages. Now, the page currently inherits from Microsoft.SharePoint.WebPartPages.WebPartPage. We need to create custom code that inherits from that class, and change the page to inherit that new custom code instead. In the custom code, override one of the OnLoad or OnInit methods, and include your check for the user's permissions there as detailed earlier. Compile the code, deploy it to your SharePoint server, and it should be functional.

If you want to set fields hidden or display them in new form or edit form page of the list...
Go to the list settings.
In Advanced Settings, enable "Allow management of content types"
By doing so, you will get a List name Link on the List Setting Page.
Open the link and select the fields that you want to hide or uhide using add or remove option.
After saving this, again disable "Allow management of content types" in Advanced Setting...
Thats it :)))

Related

Liferay: Dynamically populate 'select' structure field

I am building a liferay theme, which has two columns side by side. The right column is where the web contents will be displayed.
My implementation aims to build a menu (left column) that gets the titles from the web content titles and builds hierarchy (parent, child) based on a 'select' structure field that I added to each web content.
So far I was able to build this system using
Liferay.Service('/journalarticle/get-articles'...)
and some javascript coding.
Now the 'select' fields i use in my structure have predefined hard coded options.
How can i populate dynamically this option list so that whoever is managing content will automatically have all titles from all web contents available to choose a 'parent' from? So far a developer has to update this option list each time there is a new web content added.
#chadct : AFAIK Liferay not provide this default functionality, this is not good practice to populate dynamically value in structure field. But you wanted to achieve that functionality, then there are 4 solution :
Add one text field in structure which contains articleId of your parent web content.
You can add related article for that web content and write some sort of code to get article which consider as a parent of that web content.
Create Select DOM options form template which hold the list of article according to groupId and render on web content view mode, then you can select parent content from there and update content expando with articleId of parent webcontent. Remember this contains AJAX post request. and only show that control who is admin or loggedin user or depends on Role. Refer AJAX post calling
Hook edit_structure.jsp and add your logic here as you want.
Note : last one is worst but also a solution, Remember you need to modify your current solution.

SharePoint 2010 - Customizing the rendering and behavior of a List field

In my SharePoint List, I have an "Employee" column that is a User type field. I would like to add some custom Business Logic to the processing of this field.
Currently, when the user adds a row, I check to see if the user is an Employee or a Manager and then change the behavior on this column accordingly. I do this by statically rendering the field in my custom "ListForm Rendering Template", just before my custom ListFieldIterator. I simply use a standard SharePoint FormField (and FormLabel) control. In the markup of the FormField control, I specify the FieldName (Employee) and an event handler for the Load event. In this Load event, I will check to see if the current user is an Employee or Manager (using two different SharePoint groups). If the user is an Employee I set the value of the field to the current user (this part works perfectly). I also want to change the field so it can't be modified. I thought I might be able to just change the ControlMode on the field (in the code of the OnLoad Event Handler) to Display, but for some reason this has no effect. The field still renders with the full, people picker editor. Am I not changing the fields control mode soon enough? Or is this simply not the correct approach? The other logic I want to put in is if the user is a Manager, I would like to allow that user to select the person from a list (SharePoint group) of Employees. It may be easier to just use the people picker and limit the selectable users to that group. (I think I can do this with the SelectionGroup property.) Although, it would be better if I could just provide a dropdownlist of users, which I could possibly do with a hidden dropdownlist that I would show and event handlers that I could use (handle event selectedindexchanged) to pull the value selected and populate the (now hidden) Employee (user) field. Does this approach make sense? Assuming all that will work, the real difficulty I am having is with changing the ControlMode (rendering) on the field (when the user is an employee) to a label or some kind of read only control, which is how that field renders when viewing the row, which is why I think if I can just trick the control into thinking it is in Display mode then it should work perfectly!
I am still learning SharePoint, but I am very proficient in ASP .Net. This is why I would like to keep my customizations in this Custom Rendering Template, using code behind and leverage my existing skill set as much as properly.
Any thoughts, opinions or advice? Does anyone know why I can't get the column to switch the "Control Mode"?
I do not think that I fully understand your scenario. Some code samples could help.
But anyway it sounds like you want some heavy customizations of the user field. In that case you might want to have a look at creating a custom field with all its advantages and disadvantages. Have a look at MSDN: http://msdn.microsoft.com/en-us/library/gg132914.aspx
Another option might be - in case you do not want to re-use this column in many list definitions - that you can get away with your custom rendering template and create a custom create/edit form where you implement the specific edit behaviour for the field (plain ASP.NET with some SharePoint controls). Here is a nice walk-through on how to grab a custom edit form from SharePoint designer: http://community.bamboosolutions.com/blogs/sharepoint-2010/archive/2011/05/12/sharepoint-2010-cookbook-how-to-create-a-customized-list-edit-form-for-development-in-visual-studio-2010.aspx
I hope this helps. Kr., Bernd.

SharePoint Multiple New Item Forms

I've got a custom list with a custom content type. I'm aware that when you create a new item you can see a drop down for the different content types on that list which I assume all have their own NewForm.aspx somewhere. I can specify in the content type definition which columns are shown on the New form and that I can replace the new form with a custom one of my own design.
What I'm trying to achieve is to have multiple New forms but for the same content type listed on the New drop down. I would like each new form to expose different fields of the content type. Additionally I'd like to make particular New forms only visable by users with particular permissions although this isn't critical.
Scenario:
I've got a content type with all the fields I need for a risk assessment. When a new item is created it only exposes fields to enter contact details. Once this is created a workflow with infopath forms then drives the gathering of the rest of the risk assessment information through booking, the inspection itself and approval of the data. I want the ability to have a second option to easily enter all this information on a different new form for an inspection that's already been done and needs logging in the system.
You could customize the NewForm.aspx (e.g. via SharePoint Designer) for the initial submission case. Obviously, all of the required fields will need to be populated in some fashion.
The EditForm.aspx is the out-of-box page for updating existing list items. You may be able to customize this to meet your update an existing risk assessment case. From the post above it's not entirely clear to me whether this distinction between these pages is fully understood.
In both of these cases, you can add code-behind to the .aspx pages. However, it's usually best to start as simply as possible, keep it as simple as possible and only add complexity as necessary.
Hope this makes sense and helps. Good luck!
Dan,
Per your scenario, I have done something similar by creating one content type per actor/stage. Consider using a simple SharePoint Designer workflow to change your content types onChanged (simply by setting the Content Type) column so that the perspective actors only see the columns you want them to see in the edit/newforms. As long as the proper content type is set, your users will only see the fields you want them to see. Furthermore, with creative use of views and audience targetting of pages you can somewhat prevent these users from seeing columns.
Also, you can prevent users from seeing the different content types (under the new button) in the advanced content type page.

Adding fields to the List Forms - Sharepoint

I'm looking to add a new field onto my NewForm.aspx, EditForm.aspx and DispForm.aspx pages in Sharepoint Designer 2007. I've managed to add a new textbox webpart and have edited the Common Textbox Tasks to make the Data Field my new field (Contacts..)
But how do I edit Edit.aspx and DispForm.aspx to display this new field?
I've looked around already answered questions on the site but I haven't run across what I'm really looking for -- sorry if I missed it!
Thanks!
Shannon
It doesn't count as "development", but wouldn't creating a new List column, Site Column or Content Type add this additional field to all your list forms just fine? How does this not work in your particular case?
You have to use SharePoint Designer to access the site and edit those aspx (in the 'Forms' subfolder of the folder named after the list)
You are probably going about this the wrong way. You should not need to change the edit and new forms for a list just because you want a new field. You do need to add the field to the underlying list and rely on the code in the forms to display the field correctly.
IN SPD choose the Table tab on the far right, then Select a row, then you can Insert Above or Insert Below, then you can add your new field.
New item, edit, and display forms aren't attached to lists so much as they attached to content types. If you can't use InfoPath or Designer to set these up, what you do is the following:
Create the form in question as an application page. For whatever reason, SharePoint application pages won't render on-screen, so to get an idea of what I'm looking at I generally make them in a visual web part or separate ASP application first, then copy and paste the ASP/HTML over, then delete the original.
In the case of edit and display forms, SP will pass you a query string with the ID in it. I capture the item in question thusly:
NameValueCollection nvQueryString = Page.Request.QueryString;
taskID = Convert.ToInt32(nvQueryString["ID"]);
ViewState["TaskID"] = taskID;
SPWeb thisWeb = SPContext.Current.Web;
SPList taskList = thisWeb.Lists["Job Request approval tasks"];
SPListItem taskItem = taskList.GetItemById(taskID);
After adding on whatever it is you need to add on, you do need to add logic to the .cs page or a separate class that actually edits/adds the item in question. Probably pretty obvious...
From here you have three options: either create an event receiver that points the editformURL/displayformURL/newformURL of the content type in question to your application page, create a brand new content type and add the URL for your application page in its XML definition, or add it manually via Powershell.

Sharepoint - how to set permission level to add item but not view? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I want to allow a certain group of users to add items to a list, but not be able to view all items. This is so I can set up a workflow with certain parts of it private. I thought it'd be possible by defining a new permission level in:
http://servername/_layouts/addrole.aspx ('Add a permission level' page)
However, when you select the "add items" list permission, "view items" is automatically ticked also.
Anyone know a solution to this?
As a half-way option you can set up the list to only show items to their owner (Settings > Advanced Settings and then set options for Read Access / Edit Access as "Only their own". This won't preclude a person from seeing all items that were added by them, but there won't be anything viewable outside of this permission (other than by a list owner).
The View Items is a dependent permission for Add Items so not sure if we can add such permissions OOB in sharepoint, have a look here :
(http://office.microsoft.com/en-us/sharepointtechnology/HA101001491033.aspx)
You can have a dirty workaround of creating 2 lists and than adding the code in the item added event of the first list to add item to another list and than remove it from the first list, not sure if this is a good solution . . .
$spweb=Get-SPWeb -Identity "<site url>";
$spRoleDefinition = New-Object Microsoft.SharePoint.SPRoleDefinition;
$spRoleDefinition.Name = "Submit only";
$spRoleDefinition.Description = "Can submit/add forms/files/items into library or list but cannot view/edit them.";
$spRoleDefinition.BasePermissions = "AddListItems, ViewPages, ViewFormPages, Open";
$spweb.RoleDefinitions.Add($spRoleDefinition);
Taken from:
http://sajiviswam.wordpress.com/2011/12/09/add-only-permission-level-in-sharepoint-2010/
I had a similar problem, where didn't want anonymous users seeing contents of list.
The same solution might work for this.
In SharePoint designer (for some reason couldn't edit page on web), open the DispForm.aspx page and on webpart properties, add a target audience (if want no one to see make webpart hidden) DO NOT DELETE WEBPART - doing this breaks your list totally!
Can do the same with AllItems.aspx
Hope this helps.
Use an impersonation step in the workflow.
Out of the box with SharePoint designer I can only think to use a workflow to move any items from a Public "dropbox" list to a secured list.
A user can see and upload items to the public dropbox, but immediately a workflow kicks off that just moves the content to another, identical, secured list. You can decide if you need to allow content overwriting or not.
A hacky workaround, but that without programming that is all SharePoint is. (My company won't let me write code to it yet)
You didn't really specify which kind of list you're using, but if you look in the list settings under "Advanced Settings" you'll probably find an "Item Level Permissions" section. This will let you choose to limit users to reading (or editing) only the items they've submitted. This goes above and beyond any other ACLs set on the list or it's items.
I think use Advanced permission is not accessible since it can not prevent the one who submits from view it, otherwise it is a good solution!
Workflow should, I think, can do the job. Just make sure when an item uploaded the worklow is triggered. Then if you can build a workflow which can set specific permission to the item, all thing should be done.
If you do not get your hand dirty with building workflow then go to 3w.sharepointboost.com when have a sort of plug and play solution called Column View Permission.
I was just working on a quick solution for this, doing research when I found this message.
Besides the SPD workflow, will not work with anonymous users, I was thinking of doing a infopath html form that mails the form to a forms library. You can have one form library as the site to start the form and then have the results stored in a different forms library. Since you can set the form library to accept email from anyone you can prevent people from reading but they can still edit.
Have not tried this but if I run into problems will post comments.
I completely agree with 'Ceesaaxp'. Under Advanced Settings for the list, set Read Access to Only Their Own. I created a Knowledge Management process, whereby I created two lists, one for pending knowledge articles, and one for approved. I modified the 'New Form' page for the Pending list and disabled a drop down box using JavaScript, which was used as the status of the article. This drop down is then set permanently as 'Pending'. I also created a new permission level which allows users to Add items only. I then created a workflow which moves the article into the Approved list when the status drop down box is set to 'Approved'.
I then changed the read only settings in advanced settings of the pending list to only their own, so all knowledge articles are approved before they are published.
#Jomit. Your workaround may work, but it has the racing condition problem. Users may still have a chance to see other items. This may be a no-no depending on your rules.
Regular lists in SharePoint offer this option under Settings/Advanced Settings/Item-Level Permissions. Albeit for some reason this option is missing from the GUI for Document and Form Libraries.
One possible solution is to write a simple program to make these changes using the SharePoint Object Model.
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.writesecurity.aspx
// Sample code for setting writing and reading security on a form library
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite(args[0]))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists[args[1]];
list.WriteSecurity = 2;
list.ReadSecurity = 2;
list.Update();
}
}
}
}

Resources