Update Person metadata of uploaded documents

I followed this steps but I am having trouble updating the Person field.
https://plumsail.com/docs/forms-sp/how-to/document-meta.html

Need assistance.

var listOrLibrary = 'SPDataTable3';
var docLibraryTitle = 'Project Documents';
fd.spRendered(function() {   
    
    fd.control(listOrLibrary).$on('filesUploaded',
        function(itemIds) {
            //get document library by Title
            var library = pnp.sp.web.lists.getByTitle(docLibraryTitle);
            //go through each uploaded Item Id and set field values
            library.getListItemEntityTypeFullName().then(function(entityTypeFullName){

                var batch = pnp.sp.web.createBatch();

                for(var i = 0; i < itemIds.length; i++){
                    //specify which fields to update and how
                    library.items.getById(itemIds[i]).inBatch(batch).update({
                        Approver: fd.field('Approver1').value.DisplayText
                    }, "*", entityTypeFullName);
                    
                    alert(fd.field('Approver1').value.DisplayText);
                }

                batch.execute().then(function(){
                    fd.control(listOrLibrary).refresh();
                });
            });
        });
        
        
});

Dear @danlim26,
Welcome to the community! What seems to be the trouble? Is the field not updating, but the alert gives you the correct value? What type of field is Approver?

Yes, the alert gives the correct value. Approver field type is 'Person or Group'

Dear @danlim26,
The issue here is that you are trying to set the value of a 'Person or Group' field by display name, and it just wouldn't work...

You can try the following instead:

...
library.items.getById(itemIds[i]).inBatch(batch).update({
    Approver: fd.field('Approver1').value.EntityData.SPUserID
 }, "*", entityTypeFullName);
...

I've tried that, but it did not work.

Dear @danlim26,
Okay, and if you try adding the following before update, will you get the correct user ID in alert?

...
alert(fd.field('Approver1').value.EntityData.SPUserID);
library.items.getById(itemIds[i]).inBatch(batch).update({
    Approver: fd.field('Approver1').value.EntityData.SPUserID
 }, "*", entityTypeFullName);
...

@danlim26

You will need to add "Id" after the internal name of your People Picker field which in your case is "ApproverId" as shown in the code snippet below...
.
.
.

            for(var i = 0; i < itemIds.length; i++){
                //specify which fields to update and how
                library.items.getById(itemIds[i]).inBatch(batch).update({
                    ApproverId: fd.field('Provider').value.EntityData.SPUserID,
                    LookupFieldTestId: fd.field('DeliverableType').value.LookupId
                }, "*", entityTypeFullName);
            }

.
.
.

2 Likes