-3

I want to hide the Ribbon in Office 365 SharePoint according to the group that this user was able to extract the group to which the user belongs, I can not compare it with a string does not fall within the IF, to hide the ribbon this is my code if I can help please thanks,

var Nombre_Grup="";

$(document).ready(function() {

 $().SPServices(
 { //inicio de SPservices 
        operation: "GetGroupCollectionFromUser",
         userLoginName: $().SPServices.SPGetCurrentUser(),  
         async: false, 

                     completefunc: function(xData, Status)
                     { //inicio de completefunction

                             $(xData.responseXML).find("Group").each(function()
                             {

                                Nombre_Grup = $(this).attr("Name");

                            });
                    }
   });

console.log(Nombre_Grup);

    if(d == "Usuarios de distribución rápida")
    {
     $('#s4-ribbonrow').hide();
    }           
    else if (Nombre_Grup == "Diseñadores")
    {
    $('#s4-ribbonrow').show();
    }  

});

1 Answers1

0

Where did you initialize the value for the variable? Base on the code, the variable “Nombre_Grup” would be overwritten by the last time in the for-each loop. If you expected to compare the Nombre_Grup by everytime, you can move the code into the for-each loop like below:

$().SPServices(
{ //inicio de SPservices 
    operation: "GetGroupCollectionFromUser",
     userLoginName: $().SPServices.SPGetCurrentUser(),  
     async: false, 

                 completefunc: function(xData, Status)
                 { //inicio de completefunction

                         $(xData.responseXML).find("Group").each(function()
                         {

                            Nombre_Grup = $(this).attr("Name");
                            if (d == "Usuarios de distribución rápida") {
                                $('#s4-ribbonrow').hide();
                            }
                            else if (Nombre_Grup == "Diseñadores") {
                                $('#s4-ribbonrow').show();
                            }
                        });
                }
  });
Fei Xue
  • 14,369
  • 1
  • 19
  • 27