Sharepoint 2010 - Block and Unblock List Fields with Javascript

0

Good morning!

I'm having a problem with a Sharepoint 2010 list. We've done a Javascript code here at work that causes analysts to have two fields, locked for user editing, unlocked. The problem is that all members of the analyst group are falling into user blocking.

<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 already checked and we are all included in the group correctly.

    
asked by anonymous 14.08.2018 / 15:33

1 answer

0

Apparently your code is correct. Check the group name if you are really beating what is registered in Sharepoint.

If you want to try another way, 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
        }       
    }   
}
    
14.08.2018 / 17:04