Cannot update metadata uploaded document(s)

Good day,

I have tried to replicate this by using the same code in SharePoint Online.

But the metadata is not adjusted.

I have done this:

  1. Create a form set with rights for all user groups.
  2. Made the same form as described under "New".
  3. Used the widget to access this form on the home page of a site.
  4. Filled in "Title" with "Abc".
  5. Uploaded a document.

Result: Document is uploaded but the title is not filled.

What am I doing wrong?

The code is:

var listOrLibrary = 'SPDataTable0';
var docLibraryTitle = 'Stages';

fd.spRendered(function() {
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

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

            for(var i = 0; i < itemIds.length; i++){
                //specify which fields to update and how
                    Title: fd.field('Title').value
                }, "*", entityTypeFullName);



By the way. My goal is to stimulate users to fill out various metadata via a form that is presented on their teamsite. Then the given metadata needs to be applied to the uploaded file(s).

Hello @jruwhof,

Welcome to Plumsail Community!

Please make sure that you are using the internal name of the control in the code. You can find the internal name by clicking the control, in the left pane >> General >> Name.


And you need to use the internal name in this line:

var listOrLibrary = 'SPDataTable0';

Please update the code and test it. If metadata is not updating, please share the screenshot of the error from the browser console(F12).

Thank you. I have made sure that every name is correct by copy pasting them. In the console I recieve no errors, but the metadata is not updated.

Hello @jruwhof,

Could you please export the form and share it, so I could troubleshoot the issue.


Thank you!

Thanks. Here it is.Document DPD_New.xfds (5.8 KB)

Hello @jruwhof,

You need to make a few corrections in the code:

  1. You need to run the code under the spRendered event. You can't get the value of the fields outside of the event. Please find more information about the events here.
  2. You need to remove commas around the column names and the plus signs under the update method.

I've updated the code, please see below. Also, make sure that you are using the internal names of the fields and columns in the code.
Note that the lookup column name has 'Id' in the end of its name. For example, if the lookup column name is Products, the column name that you need to use to update the item is ProductsId.

var listOrLibrary = 'SPDataTable1';
var docLibraryTitle = 'Stages';

fd.spRendered( function() {

    var typeDocumentId = fd.field( 'Type_x0020_document' ).value.LookupId;
    var nogInOntwikkeling = fd.field( 'Nog_x0020_in_x0020_ontwikkeling' ).value;
    var werkbegeleiders = fd.field( 'Werkbegeleiders' ).value;
    var deelVanStageId = fd.field( 'Document_x0020_is_x0020_ter_x0020_voorbereiding_x0020_op_x003a_' ).value.LookupId;
    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
                    console.log( 'itemId: ' + itemIds[i] );
                    console.log( 'Type_x0020_document: ' + typeDocumentId );
                    console.log( 'Nog_x0020_in_x0020_ontwikkeling: ' + nogInOntwikkeling );
                    consloe.log( 'Werkbegeleiders: ' + werkbegeleiders );
                    console.log( 'Document_x0020_is_x0020_ter_x0020_voorbereiding_x0020_op_x003a_: ' + deelVanStageId );
                    library.items.getById( itemIds[i] ).inBatch( batch ).update({
                        Type_x0020_document: typeDocumentId,
                        Nog_x0020_in_x0020_ontwikkeling: nogInOntwikkeling,
                        Werkbegeleiders: werkbegeleiders,
                        Document_x0020_is_x0020_ter_x0020_voorbereiding_x0020_op_x003a_: deelVanStageId
                    }, "*", entityTypeFullName );


If the code is not working, please share any error that ou get in the browser console(F12), e.g.

Sorry for my late reply. Thank you for your support!
For now, the customer requirements have changed and there is no need fur this solution yet.

1 Like