Update uploaded files - Error HttpClient

Hi,

I use the script from https://plumsail.com/docs/forms-sp/how-to/document-meta.html to Update uploaded files and it works but sometimes (most when I do a second upload in the same control). I get this message:
"Uncaught (in promise) Error: Error making HttpClient request in queryable: [400] Bad Request"

Thanks in advance,

Daniël

//Some parts of my script:

var docLibraryId = 'fffb777f-9cc7-42bf-9ee1-e5daca0e7036';
var batch = pnp.sp.web.createBatch();

function SetFilename(itemIds, v) {
            //get document library by Title
            var library = pnp.sp.web.lists.getById(docLibraryId);
            //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 - FileLeafRef: fd.field('Title').value
                    console.log(library.items.getById(itemIds[i]));
					library.items.getById(itemIds[i]).inBatch(batch).update({
						FileLeafRef: strInstellingsNummer + '_' + strVestigingVolgNr + '_' + (new Date).getFullYear() + '_' + v  + '_(' + i + ')',
						Categorie: v
                    }, "*", entityTypeFullName);
                }

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

fd.spRendered(function(vue) {

		fd.control('Investeringsplan').$on('filesUploaded', function(itemIds) {
			SetFilename(itemIds, 'Investeringsplan')
        });

		fd.control('Offerte').$on('filesUploaded', function(itemIds) {
			SetFilename(itemIds, 'Offerte')
        });
		
		fd.control('Schilderwerken_Patrimonium').$on('filesUploaded', function(itemIds) {
			SetFilename(itemIds, 'Schilderwerken_Patrimonium')
        });
		
		fd.control('Bijlage').$on('filesUploaded', function(itemIds) {
			SetFilename(itemIds, 'Bijlage')
        });
		
    
 });

Hello @danieljr,

The filename in the library should be unique. And if you upload the batch of files twice, you will have duplicate names because of this line.

ileLeafRef: strInstellingsNummer + '_' + strVestigingVolgNr + '_' + (new Date).getFullYear() + '_' + v  + '_(' + i + ')',

In which i is the position of the file in the batch.

So to fix this, you can either change this line or set the Title of the file instead of Filename.