Hello @jruwhof,
You need to make a few corrections in the code:
- 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.
- 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 );
}
batch.execute().then(function(){
fd.control(listOrLibrary).refresh();
});
});
});
});
If the code is not working, please share any error that ou get in the browser console(F12), e.g.