1

I want to add list item with multiple people picker column, how can add multiple users in my list column?

I can successfully add single people picker item, but not multiple. My code is working fine with adding single people picker item.

My code:

var ctx = new SP.ClientContext(appWebUrl);
        var appCtxSite = new SP.AppContextSite(ctx, spHostUrl);
        var web = appCtxSite.get_web(); 
        var list = web.get_lists().getByTitle("GNPages");

        var listCreationInformation = new SP.ListItemCreationInformation(); 
        var listItem = list.addItem(listCreationInformation);

        var processContri = new Array();
        angular.forEach(ppMultiVal, function (value, key) {
            console.log(value.name);
            processContri.push(SP.FieldUserValue.fromUser(value.name));
        });

        listItem.set_item("Title", title);
        listItem.set_item("Description", descr);
        listItem.set_item("ProcessOwner", ppSingleVal.Id);
        listItem.set_item("ProcessContributer", processContri);
        listItem.update();

        ctx.load(listItem);
        //Execute the batch Asynchronously
        ctx.executeQueryAsync(
            Function.createDelegate(this, success),
            Function.createDelegate(this, error)
           );
  • Have you tried a semicolon and pound delimited value in the syntax of userid1;#username1;#userid2;#username2 – T0t3sMcG0t3s Jul 28 '16 at 22:00
  • processContri.push(SP.FieldUserValue.fromUser(value.Name)); Thanks for this post its working fine. – dfgdf Sep 19 '17 at 9:40
1

I resolved this way, and its working fine now with adding single PP field and Multiple PP field to a List...

HEre is my code:

        $scope.saveNewPage = function () {
        var title = $scope.newPage.title;
        var descr = $scope.newPage.description; 
        var ppSingleVal = $scope.vm.data.su;
        var ppMultiVal = $scope.vm.data.mu;

        var ctx = new SP.ClientContext(appWebUrl);
        var appCtxSite = new SP.AppContextSite(ctx, spHostUrl);
        var web = appCtxSite.get_web(); 
        var list = web.get_lists().getByTitle("GNPages");

        var listCreationInformation = new SP.ListItemCreationInformation(); 
        var listItem = list.addItem(listCreationInformation);

        var processContri = new Array();
        angular.forEach(ppMultiVal.results, function (value, key) {
            console.log(value.Name)
            processContri.push(SP.FieldUserValue.fromUser(value.Name));
        });
        console.log(processContri);
        listItem.set_item("Title", title);
        listItem.set_item("Description", descr);
        listItem.set_item("ProcessOwner", ppSingleVal.Id);
        listItem.set_item("ProcessContributer", processContri);
        listItem.update();

        ctx.load(listItem);
        //Execute the batch Asynchronously
        ctx.executeQueryAsync(
            Function.createDelegate(this, success),
            Function.createDelegate(this, error)
           );

        function success() {
            console.log('success');
        }

        function error(sender, args) {
            console.log(args.get_message() + '\n' + args.get_stackTrace());
        }

    }
0

You should do something like this

var revisor = $("#cppRevisor").getUserInfo().Id;
LookupField.set_lookupId(revisor);
newItem.set_item('Revisor', LookupField);

var aprobador = $("#cppAprobador").getUserInfo().Id;
LookupField.set_lookupId(aprobador);
newItem.set_item('Aprobador', LookupField);

Where $("#cppRevisor").getUserInfo().Id and $("#cppAprobador").getUserInfo().Id Is the user's id I use spspeoplepicker.js to work with peoplepicker.

I hope this helps you.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.