Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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";
        }
    }
}

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).

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

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.

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.

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.

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.

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

Well it has been few years from the question was created, but it can help others.

I created another column as lookup and referred the original column, then modified the view unchecked the original column, that's it.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top