Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to create a read-only column in my "Request Approval" Nintex workflow task that I sent to the user. I did the following:

  1. Created a column in my list. Field name: “Guideline”
  2. In the default view this column is not displayed
  3. Created content types that contains the Guideline column.
  4. Content type name: “Workflow task”
  5. This is the default content type
  6. Now when the user is approving an item, he sees the “guideline” field

However the field is in edit mode and the user can add information to this field. I want to prevent from the user to edit this field!

What should I do?

share|improve this question
1  
Does the content in the Guideline field change for every item? If not can you not just make it a static text within the workflow task notification? –  Karthik Murugesan May 15 '11 at 10:52
add comment

9 Answers

up vote 8 down vote accepted

To achieve true column level security in SharePoint, I work with two lists and create the column as a lookup. This way, I can set specific permissions on the lookup source (e.g. read only or even access denied).

It requires more effort than a single list, but as far as I know this is the only way without server-side code. But in case of only a single list,means if we require only one list and can't add any other list then we face a problem.

share|improve this answer
add comment

You can customize the editform.aspx using SharePoint Designer. Take a look at the article below to see how to do this.

http://office.microsoft.com/en-us/sharepoint-designer-help/create-a-custom-list-form-HA010119111.aspx

"In step 6 - Under Type of form to create, indicate whether you want to create a New item form, an Edit item form, or a Display item form."

You will choose "Edit item form". Once you create this form go through the source code and locate the HTML snippet that displays "Guideline" field. You can comment this section to prevent users from editing. Or change the edit mode to "Display" to show the users read only content.

Final thoughts - If the content in the Guideline field doesn't change for every item, just make it Guideline a static text within the workflow task notification. Don't create it as a field. That way users will see a Guideline text as part of the approval notification.

share|improve this answer
add comment

The bottom line is that there is no such thing as a "read-only column" in SharePoint. You can mask it, hide it, etc., but there may still be a place (usually the datasheet view is a culprit) where a user can enter data into it.

Customizing the forms is the best approach for reliability over script. (Anyone who knows me knows I love working with script!) If you protect the column using script and the script doesn't run for any reason, then the column won't be protected. (This might just be due to your own bug in the script.)

You can customize forms in SharePoint Designer or in managed code.

share|improve this answer
add comment

You could use an item event receiver that prevents the value from being changed. Something like this:

public class EventReceiver1 : SPItemEventReceiver
{
    public override void ItemUpdating(SPItemEventProperties properties)
    {
        if (properties.ListItem["Guideline"] != properties.AfterProperties["Guideline"])
        {
            properties.Cancel = true;
            properties.ErrorMessage = "Guideline is a read-only field";
        }
    }
}
share|improve this answer
1  
Its a good idea to use this technique in combination with the UI based approaches as this event receiver will cancel the edit after the user has pressed save and may cause other important edits to be lost. This is then used as a failsafe to prevent any edits that come via direct object model calls or web service calls. –  Steve P May 16 '11 at 6:06
1  
Alternatively, simply discard the change and force AfterProperties to be equal to BeforeProperties. –  Kit Menke May 16 '11 at 16:14
    
@Kit I didn't know that worked! Its not explicitly documented but other members of the community have used it. msdn.microsoft.com/en-us/library/… –  Steve P May 18 '11 at 5:36
add comment

I completely agree with @Marc D Anderson and @Matt Weimer. You can use JavaScript to help with the UI presentation and an event receiver to enforce the values server-side.

As for the JavaScript portion, I suggest taking a look at SPUtility.js (full disclosure, I maintain this open source library). It allows you to do the following:

<script type="text/javascript">
function InitializeMyForm()
{
    SPUtility.GetSPField('Guideline').MakeReadOnly();
    // more code here...
}
_spBodyOnLoadFunctionNames.push("InitializeMyForm");
</script>

This could go in a Content Editor Web Part on your form (see the installation page for more options).

share|improve this answer
add comment

If you are describing the column as a site column in a feature, you could add the ReadOnly attribute (set to TRUE) along with the following attributes:

PITarget="" PrimaryPITarget="" PIAttribute="" PrimaryPIAttribute="" Node=""

In order to make the site column ReadOnly and only updatable via code. I haven't tested this to see if one can override it with the DataSheet view; but I would have thought not.

share|improve this answer
    
It works! I'v been searching for how to make field ReadOnly for users in WSS3 but still allow updating field value programmatically in code. Thank you for solution. And the DataSheet view says the field is read only - you cannot edit it as expected. Note that SharePoint Foundation has FieldRef attribute ReadOnlyClient. Another note: If we set ShowInDisplayForm, then the field appears in display form, but if we set ShowInEditForm, the field won't appear there (also expected behaviour). –  Janis Veinbergs Mar 8 '12 at 15:22
add comment

I've explored another approach to this which uses the object model to set the ReadOnlyField property (see: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfield.readonlyfield.aspx).

SPList list = web.Lists["Your list name"];
SPField guideline = list.Fields["Guideline"];
guideline.ReadOnlyField = true;
guideline.Update();  

Once this has been done to a field, it will no longer show up the new item and edit item forms. The drawback here is when you add new item to the list and you want to set the initial value for the read-only column. You would need to change the value of the ReadOnlyField property back to false, add the item, then set the ReadOnlyField property back to true. The same process would be needed if changing the value of the read-only field. Furthermore, I tested to see what happens when you try to change the value through code with this property set to true. It does not generate any exceptions or errors, it simply discards the new value.

share|improve this answer
add comment

look at this tools it's helpful for making columns readonly or hidden http://splistsecurity.codeplex.com/

share|improve this answer
    
Hi and welcome! When you promote your own blog or similar you should always state this in your post! Please add this disclaimer. Also please read our FAQ regarding self promotion. –  Anders Rask Nov 29 '12 at 9:58
add comment

Search the Read only column in SharePoint list , and see the SharePointBoost Column/View Permission can do this well.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.