0

I've got a custom page that allows the site administrators to manage users on two different site collections. One of the tools is a button that adds that user to the same group on those two site collections at the same time using SPServices "AddUserToGroup." The button is fed by a dropdown list of all of our groups:

    $().SPServices({
    operation: "GetGroupCollectionFromSite",
    async: false,
    completefunc: function (xData, Status) {
        $(xData.responseXML).find("Group").each(function() {

            var groupTitle = ($(this).attr("Name")).replace((/&/g, "&"));

            $("#groupNames").append(
                '<option value="' + groupTitle + '">' + groupTitle + '</option>' 
            );
        });         
    }
    });
    $("#addButton").click(function() {
    var value = String($('#groupNames').val());
    addToGroup(value);

    });

The button (with the ID of "addButton") then performs the following task:

    $().SPServices({
        operation: "AddUserToGroup",
        groupName: groupName,
        userLoginName: accountName,
        completefunc: function(data,status){

        }
    });     
    $().SPServices({
        operation: "AddUserToGroup",
        webURL: "/sites/othersite/",
        groupName: groupName,
        userLoginName: accountName,
        completefunc: function(data,status){

        }
    });     

Every other group works perfectly and it does exactly what it should do. But if I get a group with an ampersand in it, it fails. I've tried regex (as you see in the groupTitle variable), I've tried pushing the name to a string, I've tried adding quotations around it in the service call... but nothing works. I know there shouldn't be ampersands in the group names to begin with, but there's not much I can do about that at the moment.

Does anyone know what I can do to make this work with the ampersand?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.