Sharepoint 2010 - Blocking and Unlocking List Fields with Javascript

Asked

Viewed 154 times

0

Good morning!

I have a problem with a Sharepoint 2010 list. We made a Javascript code here at work that makes analysts have two fields, blocked for user editing, unlocked. The problem is that all members of the analyst group are falling into user block.

<script src="/-/js/jquery-3.1.1.min.js" type="text/javascript"></script>
<script src="/-/js/spjs-utility.js" type="text/javascript"></script>
<script src="/-/js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="/strategy/sp/js/jquery.SPServices-2014.01.min.js"></script>
<script type="text/javascript">
    $().SPServices({ 
        operation: "GetGroupCollectionFromUser",
        userLoginName: $().SPServices.SPGetCurrentUser(),
        async: false,
        completefunc: function (xData, Status) {
            if (($(xData.responseXML).find("Group[Name='nomedogrupo']").length == 1)) {
                campos que devem ser bloqueados para analistas
            }
            else{
                campos que devem ser bloqueados para usuários
            } 
        } 
    });
</script>

What could be causing the problem? I have checked and we are all included in the group correctly.

1 answer

0

Apparently your code is correct. Check the name of the group if it is actually matching what is registered in Sharepoint.

If you want to try otherwise follow a solution without using Spservices:

$(document).ready(function ($) {
    ExecuteOrDelayUntilScriptLoaded(VerificarPermissoes, "SP.ClientContext");       
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', VerificarPermissoes);
});

function VerificarPermissoes() {
    var clientContext = SP.ClientContext.get_current(); 
    var currentUser = clientContext.get_web().get_currentUser();    
    clientContext.load(currentUser);
    var userGroups = currentUser.get_groups();  
    clientContext.load(userGroups); 
    clientContext.executeQueryAsync(OnQuerySucceeded);

    function OnQuerySucceeded() {  
        var ehAnalista = false; 
        var groupsEnumerator = userGroups.getEnumerator();          

        while (groupsEnumerator.moveNext()) {   
            var group = groupsEnumerator.get_current().get_title(); 

            if(group == "Nome do Grupo Analistas"){ 
                ehAnalista = true;
            }
        }   

        if(ehAnalista){
            //campos que devem ser bloqueados para analistas
        }
        else{
            //campos que devem ser bloqueados para usuários
        }       
    }   
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.