Related-item Readonly

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
ksertkaya
Posts: 87
Joined: Wed Nov 18, 2015

27 Jun 2019

Hello,

Can I set readonly this related-items' column according to group permission?

Code: Select all

  IsCurrentUserMemberOfGroup("Test Users", function (isCurrentUserInGroup) {
    if(!isCurrentUserInGroup)
    {
...    // set readonly
    }
  });
}
Thanks.
Screenshot_3.png
Screenshot_3.png (40.77 KiB) Viewed 5222 times

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

27 Jun 2019

Dear Sertkaya,
We do not offer such functionality out of box, there should be solutions to this question as Related Items uses SharePoint's default List view. You can check out this thread for an example of possible solution - https://sharepoint.stackexchange.com/qu ... n-gridview
Cheers

ksertkaya
Posts: 87
Joined: Wed Nov 18, 2015

11 Jul 2019

I think this code should work but not :cry:

Code: Select all

$('tr>td[role="gridcell"]:nth-child(3)').attr("aria-readonly","true");

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

11 Jul 2019

Hello!

Please do the following:

1. create the .txt file and paste the code below in it. Make sure to enclose it in <Script> tags. Save the file to Sharepoint Document library on your site. Replace {Colum_to_hide} with your field's internal name;

2. add the Content Editor web part to the view page. Edit web part and paste the link to the .txt file in Content link;

3. in the Web Part Advanced setting specify the group you want to hide the field from in Target Audiences. Click OK and test it.

Code: Select all

<script>
var updateViewerFields=["{Colum_to_hide}"];
(function updateView() {
    var overrideContext = {};
    overrideContext.Templates = overrideContext.Templates || {};
    overrideContext.Templates.OnPreRender = function(ctx) {
 
       for(j=0; j<ctx.ListSchema.Field.length; j++)
       {
          var f = ctx.ListSchema.Field[j];
          for(i=0;i<updateViewerFields.length;i++){
             if(f.DisplayName == updateViewerFields[i]){
                f.AllowGridEditing=false;
             }
          }
       }
    } 
 SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext);
 })(); 
</script>
Please let me know how that worked out for you.

ksertkaya
Posts: 87
Joined: Wed Nov 18, 2015

16 Jul 2019

mnikitina wrote:
11 Jul 2019
Hello!

Please do the following:

1. create the .txt file and paste the code below in it. Make sure to enclose it in <Script> tags. Save the file to Sharepoint Document library on your site. Replace {Colum_to_hide} with your field's internal name;

2. add the Content Editor web part to the view page. Edit web part and paste the link to the .txt file in Content link;

3. in the Web Part Advanced setting specify the group you want to hide the field from in Target Audiences. Click OK and test it.

Code: Select all

<script>
var updateViewerFields=["{Colum_to_hide}"];
(function updateView() {
    var overrideContext = {};
    overrideContext.Templates = overrideContext.Templates || {};
    overrideContext.Templates.OnPreRender = function(ctx) {
 
       for(j=0; j<ctx.ListSchema.Field.length; j++)
       {
          var f = ctx.ListSchema.Field[j];
          for(i=0;i<updateViewerFields.length;i++){
             if(f.DisplayName == updateViewerFields[i]){
                f.AllowGridEditing=false;
             }
          }
       }
    } 
 SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext);
 })(); 
</script>
Please let me know how that worked out for you.
Hello,

Thanks for your help. Unfortunately not working :oops:

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

16 Jul 2019

Ksertkaya,

I had a look at your screenshot. If you are pasting the code in the Script Editor, please remove the <Script> tags.

Also please test it without adding the Target Audience group.

ksertkaya
Posts: 87
Joined: Wed Nov 18, 2015

25 Jul 2019

I added this code like this but now working :(
Screenshot_8.png
Screenshot_8.png (38.82 KiB) Viewed 5157 times

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

26 Jul 2019

Ksertkaya,

Please remove {} from the second line, so the line would look lite that:

var updateViewerFields=["Kazanim"];

ksertkaya
Posts: 87
Joined: Wed Nov 18, 2015

29 Jul 2019

Stiil not working :(

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

31 Jul 2019

Ksertkaya,

Please send the screenshot from the console (F12) so I could troubleshoot the issue.

Also, you can refer to this post to try another workaround example.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests