Saya mendapatkan teks tampilan dan email pengguna tetapi saya tidak tahu cara memasukkannya ke kolom 'orang atau grup'.

function getUserInfo(PeoplepickerId) {  
    var UsersID="";
    var peoplePicker = this.SPClientPeoplePicker.SPClientPeoplePickerDict[PeoplepickerId + "_TopSpan"];  

        if (peoplePicker.HasInputError) return false; // if any error  
        else if (!peoplePicker.HasResolvedUsers()) return false; // if any invalid users  
        else if (peoplePicker.TotalUserCount > 0) {  
            // Get information about all users.  
            var users = peoplePicker.GetAllUserInfo();  
            //var userInfo = '';  
            //var promise = '';  
             for (var i = 0; i < users.length; i++) {  
                 UsersID += users[i].DisplayText + "\n";
                 UsersID += users[i].EntityData.Email;
             }  
             return UsersID;  
        }       
    } 
0
Kuldeep 2 Januari 2018, 12:57

1 menjawab

Jawaban Terbaik

Anda dapat menggunakan JSOM untuk memasukkan data ke dalam daftar SharePoint Anda seperti di bawah ini:

var ctx = new SP.ClientContext.get_current();

var list = web.get_lists().getByTitle("Custom List");
var listCreationInformation = new SP.ListItemCreationInformation();
var listItem = list.addItem(listCreationInformation);           

// Get user keys.
var keys = peoplePicker.GetAllUserKeys();
var finalusers = new Array();
for (var i = 0; i < users.length; i++) {
    var arrayuser = users[i];
    finalusers.push(SP.FieldUserValue.fromUser(arrayuser.Key));
}
listItem.set_item("PeopleColumnInternalName", finalusers);
listItem.update();
ctx.load(listItem);

ctx.executeQueryAsync(function(){
    console.log("inserted successfully");
}, function(){
    console.log("something went wrong");
});

Jadi, Anda dapat memodifikasi kode Anda seperti di bawah ini. Ganti dengan nama daftar Anda dan nama internal kolom pengguna:

function getUserInfo(PeoplepickerId) {  
    var UsersID="";
    var peoplePicker = this.SPClientPeoplePicker.SPClientPeoplePickerDict[PeoplepickerId + "_TopSpan"];  

        if (peoplePicker.HasInputError) return false; // if any error  
        else if (!peoplePicker.HasResolvedUsers()) return false; // if any invalid users  
        else if (peoplePicker.TotalUserCount > 0) {  
            // Get information about all users.  
            var users = peoplePicker.GetAllUserInfo();  
            //var userInfo = '';  
            //var promise = '';  
             for (var i = 0; i < users.length; i++) {  
                 UsersID += users[i].DisplayText + "\n";
                 UsersID += users[i].EntityData.Email;
             }

            //insert data to sharepoint
            var ctx = new SP.ClientContext.get_current();

            var list = web.get_lists().getByTitle("Custom List");
            var listCreationInformation = new SP.ListItemCreationInformation();
            var listItem = list.addItem(listCreationInformation);           

            // Get user keys.
            var keys = peoplePicker.GetAllUserKeys();
            var finalusers = new Array();
            for (var i = 0; i < users.length; i++) {
                var arryuser = users[i];
                finalusers.push(SP.FieldUserValue.fromUser(arryuser.Key));
            }
            listItem.set_item("PeopleColumnInternalName", finalusers);
            listItem.update();
            ctx.load(listItem);

            ctx.executeQueryAsync(function(){
                console.log("inserted successfully");
                return UsersID;
            }, function(){
                console.log("something went wrong");
                return UsersID;
            });

        }       
} 
1
Gautam Sheth 2 Januari 2018, 11:10