Create a form set with rights for all user groups.
Made the same form as described under "New".
Used the widget to access this form on the home page of a site.
Filled in "Title" with "Abc".
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() {
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({
Title: fd.field('Title').value
}, "*", entityTypeFullName);
}
batch.execute().then(function(){
fd.control(listOrLibrary).refresh();
});
});
});
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).
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).
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.