List and Library rename the file on upload

Hello @Rinu,

Please try out the code below.

var listOrLibrary = 'SPDataTable1';
var docLibraryTitle = 'fileUploadListTest';
var docLibraryId = '32398E41-12E4-4E25-8618-670FB69362C7';

 var extension;
 var filename;
fd.spRendered(function() {
    fd.control(listOrLibrary).$on('filesUploaded',
        function(itemIds) {
            //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();
                var currentName;
                var uri;
               

                for(var i = 0; i < itemIds.length; i++){
                    //specify which fields to update and how
                    var itemId = itemIds[i];
                    library.items.getById(itemId).inBatch(batch).update({Title: fd.field('Title').value}, "*", entityTypeFullName);
                    batch.execute();
                    
                    library.items.getById(itemId).select('FileRef', 'Id').get().then(function(item){
                        return item	
                    
                     }).then(function(item){
                         uri = item.FileRef;
                         var fileID  = item.Id;
					     filename = uri.substring(uri.lastIndexOf("/")+1,uri.lastIndexOf(".")) + '_' + fileID;
                         var nbatch = pnp.sp.web.createBatch();
                         library.items.getById(fileID).inBatch(nbatch).update({FileLeafRef: filename}, "*", entityTypeFullName)
                            nbatch.execute().then(function(){
                                fd.control(listOrLibrary).refresh();
                            });
                     });
                   }
            });
        });
});