如何使用SPservices将多个用户添加到Item

时间:2013-05-22 06:25:41

标签: jquery sharepoint spservices

如何使用SPservices将多个用户添加到包含多个用户的Item?在JQuery中可以吗?

我有下一个jquery:

//Users ID, who shoud be located in the field "Users"
var us1 = 110; 
var us2 = 113;
var uw3 = 115;


$().SPServices({
        operation: "UpdateListItems",
        async: false,
        batchCmd: "Update",
        listName: "testList",
        valuepairs: [["users", us1]],
        ID: 5, 
        completefunc: function(xData, Status) {
             alert("yeah, ready!");
    });
}

现在字段[“users”]具有“多个用户”类型,此方法仅添加一个用户(us1)。 那么,我如何向几个用户(us1,us2,us3)添加字段[“用户”]?

1 个答案:

答案 0 :(得分:1)

我知道这个问题已经有一年了,但我发现它并没有答案,因此:更新用户字段有多个选择(添加和删除用户)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js">

function UpdateParticipants(listName, itemId, userName, userId, initialData) {

    var usersToSet = "";
    if (!IsStringEmpty(initialData)) {
        usersToSet = initialData + ";#" + userId + ";#" + userName;
    } else {
        usersToSet = userId + ";#" + userName;
    }

    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        debug: true,
        listName: listName,
        ID: itemId,
        valuepairs: [["EventParticipants", usersToSet]],
        completefunc: function (xData, Status) {
            if (Status != "success") {
                alert("Something Went Wrong. You haven't applied for the event, please contact Event Manager.");
            } else {
                alert("You have succesfully applied for the event.");
            }
        }
    });

}

function RemoveParticipant(listName, itemId, userName, userId, initialData) {

    var usersToDelete = userId + ";#" + userName;
    var usersToSet = initialData.replace(usersToDelete, "");

    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        debug: true,
        listName: listName,
        ID: itemId,
        valuepairs: [["EventParticipants", usersToSet]],
        completefunc: function (xData, Status) {
            if (Status != "success") {
                alert("Something Went Wrong. You haven't resigned from the event, please contact Event Manager.");
            } else {
                alert("You have succesfully resigned from the event.");
            }
        }
    });

}

function IsStringEmpty(inputString) {
    if (inputString != null && inputString != "" && inputString != "undefined" && inputString.length > 0) {
        return false;
    }
    return true;
}

  
</script>

listName - 实际上是我的情况下列出GUID ......:)