1

In sharepoint 2016 I have a list with several views each targeting different audience. I need some solution to manage column permission in new/edit/display forms. I tried https://archive.codeplex.com/?p=sp2013columnpermission but I could not download the wsp file described (download gets .git folder which can not fetch any branches: not found). Why sharepoint has some easy solution to render target audience to list views but has no out-of the box solution for managing the list forms of these views? Do you have any idea how to get it? I tried also jquery like: How to hide SharePoint list columns from users based on permission but simply did not hide the column (jquery was loaded).

Thanks!

2 Answers 2

0

Here is my sample tested script, while you need update the jQuery selector based on your filed type and group title.$("input[title='testNumber']") just select single line text filed title as testNumber.

<!-- jQuery Reference. You can refer it from Layouts Folder/Doc Library too, after uploading the script. -->
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

    <!-- Download SPServices from: http://spservices.codeplex.com/ Or use this CDN  -->
    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $().SPServices({
                operation: "GetGroupCollectionFromUser",
                userLoginName: $().SPServices.SPGetCurrentUser(),
                async: false,
                completefunc: function (xData, Status) {
                    var _PerCheck = false;
                    $(xData.responseXML).SPFilterNode("Group").each(function () {
                        var currentGroup = $(this).attr("Name");                        
                        if (currentGroup == 'Developer Owners') {
                            _PerCheck = true;
                        }                        
                    })
                    if (!_PerCheck) {
                        $("input[title='testNumber']").closest('tr').hide();
                    }
                }
            });
        });
    </script>
2
  • Hi Lee_MSFT! You code works if I change to " if (_PerCheck) { " but only in Edit/New list forms. Unfortunatelly it does not hide the field in the Display form (view item). Do you have any ideas how to hide it? And how can I make field to show "Read only" in New/Edit form?
    – Ivanhou
    Oct 1, 2018 at 12:58
  • The control display as different html in display form, for display form, use $('td.ms-formlabel:contains("testNumber")').closest('tr').hide();
    – Lee
    Oct 2, 2018 at 6:41
0

I managed to hide column in New/Edit listform, this code works for me in scripteditor:

<script language="javascript" type="text/javascript" src="/sites/mysite/SiteAssets/Scripts/jquery-3.3.1.min.js"></script><script language="javascript" type="text/javascript" src="/sites/mysite/SiteAssets/Scripts/jquery.SPServices.min.js"></script>    <script type="text/javascript">        $(document).ready(function () {            $().SPServices({                operation: "GetGroupCollectionFromUser",                userLoginName: $().SPServices.SPGetCurrentUser(),                async: false,                completefunc: function (xData, Status) {                    var _PerCheck = false;                    $(xData.responseXML).SPFilterNode("Group").each(function () {                        var currentGroup = $(this).attr("Name");                                                if (currentGroup == 'GroupName') {                            _PerCheck = true;                        }                                            })                    if (_PerCheck) {                                              $("input[title='Status']").parent().parent().parent().hide();                     }                }            });        });    </script>

For DisplayForm I used this code:

<script language="javascript" type="text/javascript" src="/sites/mysite/SiteAssets/Scripts/jquery-3.3.1.min.js"></script><script language="javascript" type="text/javascript" src="/sites/mysite/SiteAssets/Scripts/jquery.SPServices.min.js"></script><script type="text/javascript">        $(document).ready(function () {            $().SPServices({                operation: "GetGroupCollectionFromUser",                userLoginName: $().SPServices.SPGetCurrentUser(),                async: false,                completefunc: function (xData, Status) {                    var _PerCheck = false;                    $(xData.responseXML).SPFilterNode("Group").each(function () {                        var currentGroup = $(this).attr("Name");                                                                      if (currentGroup == 'GroupName') {                            _PerCheck = true;                        }                                            })                    if (_PerCheck) {                        $('td.ms-formlabel:contains("Status")').parent().hide();                    }                }            });        });    </script>

Read-only column: I created a new calculated column referencing the required one.

Thank You!

Your Answer

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

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