15

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?

1
  • 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? Commented May 15, 2011 at 10:52

10 Answers 10

10

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.

4
  • 6
    Note: the last sentence was added by a moderator and I have no idea what it means.
    – Christophe
    Commented Mar 6, 2015 at 16:53
  • I added an edit to remove the nonsense sentence, but apparently it needs to be "peer reviewed". XD Commented May 18, 2019 at 0:31
  • I'm trying this but I've changed the permissions on the source list to Read and a user can still change this column. Am I missing something? Commented Jan 30, 2020 at 15:22
  • I'm trying to remember what I meant 8 years ago... But basically the idea is that the user can only pick what you put in the source list, not change to his/her own values. And of course the value would be frozen if the source list only has one item.
    – Christophe
    Commented Jan 31, 2020 at 4:41
6

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";
        }
    }
}
4
  • 2
    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
    Commented May 16, 2011 at 6:06
  • 2
    Alternatively, simply discard the change and force AfterProperties to be equal to BeforeProperties.
    – Kit Menke
    Commented May 16, 2011 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
    Commented May 18, 2011 at 5:36
  • So... how would you set the property in the first place? -- Seems like this field would just always be null with no way to change that. Commented May 18, 2019 at 0:32
3

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

3

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

1
  • 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. Commented Nov 29, 2012 at 9:58
2

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.

2

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.

2

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.

1
  • 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). Commented Mar 8, 2012 at 15:22
2

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.

0

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

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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