Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

jQuery SPGetCurrentUser undefined

$
0
0

Hello everyone!

I have a list that contains multiple scripts with different jQuery libraries.

One of them, consist of hiding multiple columns for a specific group permissions. This script works perfectly when i add it alone in a list. Meanwhile, when i have added this script into the list that got multiple scripts it doesn't work anymore.

I expect because i am using multiple jQuery libraries in the same list.

Here is my script:

<script src="https://code.jquery.com/jquery-1.11.0.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.01/jquery.SPServices.min.js"></script><script type="text/javascript">
       $(function () {
            var currentUser = $().SPServices.SPGetCurrentUser();
            console.log(currentUser);
            $().SPServices({
                operation: "GetGroupCollectionFromUser",
                userLoginName: currentUser,
                async: false,
                completefunc: function (xData, Status) {
                    var flag = ($(xData.responseXML).find("Group[Name='ZwZ ViewOnly']").length == 1);
                    if (flag) {
                        HideFieldByName("Test");
                        HideFieldByName("Test1"); 
                    }
                }
            });
        });
        function HideFieldByName(fieldName)
        {
		    var header = document.querySelectorAll("[displayname=" + fieldName + "]")[0].parentNode;
			var index = [].slice.call(header.parentNode.children).indexOf(header) + 1;
			header.style.display = "none";
		     for (var i = 0, cells = document.querySelectorAll("td:nth-child(" + index + ")"); i < cells.length; i++) 
		    {
			  cells[i].style.display = "none";
		    }
        }</script>

Here are the libraries i am using:

Here is the error i am getting in the console:

Also,I am using 2 different permissions in the same list for the same users in SharePoint group and as user,this script will only hide the columns for the user that exist in a group. Do you think it will affect and display columns if the user has also a permission based on user type ?

Here is a screenshot what i mean:

Any suggestions how to fix this issue ?

Any help will be greatly appreciated.

Thank you!



Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>