Page 1 of 1

Related-item Readonly

Posted: 27 Jun 2019
by ksertkaya
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 5223 times

Re: Related-item Readonly

Posted: 27 Jun 2019
by Nikita Kurguzov
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

Re: Related-item Readonly

Posted: 11 Jul 2019
by ksertkaya
I think this code should work but not :cry:

Code: Select all

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

Re: Related-item Readonly

Posted: 11 Jul 2019
by mnikitina
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.

Re: Related-item Readonly

Posted: 16 Jul 2019
by ksertkaya
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:

Re: Related-item Readonly

Posted: 16 Jul 2019
by mnikitina
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.

Re: Related-item Readonly

Posted: 25 Jul 2019
by ksertkaya
I added this code like this but now working :(
Screenshot_8.png
Screenshot_8.png (38.82 KiB) Viewed 5158 times

Re: Related-item Readonly

Posted: 26 Jul 2019
by mnikitina
Ksertkaya,

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

var updateViewerFields=["Kazanim"];

Re: Related-item Readonly

Posted: 29 Jul 2019
by ksertkaya
Stiil not working :(

Re: Related-item Readonly

Posted: 31 Jul 2019
by mnikitina
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.