Combine three JS functions into one

I have these functions that you can see below. The functions all works (alone). The functions only work with the excact Google DOC ID that I entered directly in the script.

So I want to build the getListOfId() and moveSheet1() function into the getDocItems() and runsies() functions.

The variable -> var docFilesId = []; in the getListOfId() function contains all Google Doc files IDS from the folder that are in my Google Drive.

That means: the function runsies() should be repeated and executed until all documents have been read out and all data has been gradually written into the cell.

I tried a loop, but unfortunately it didn’t work. I don’t know how I can integrate the IDS “var = docFilesID ” into the other functions.

Short Summary:

  1. Function is executed ->
  2. Cell is checked whether it is empty ->
  3. If the cell is not empty, it is moved down one cell ->
  4. All Google DOC IDS from the folder are read and stored in the array ->
  5. The first ID from thies array above is used ->
  6. Data from the Google DOC are read out and stored in an another array ->
  7. Data in second array are entered in the cell->
  8. -> -> -> ->
  9. The sequence is carried out until all IDS have been run through -> -> ->
function getDocItems(docID, identifier){
      const body = DocumentApp.openById("13TlciLOZV-rxj1aV4qFdeBoMuEocGNgCSb7_uXXoZDQ").getBody();
      const docText = body.getText();
      
      //Check if search characters are to be included. 
      let startLen =  identifier.start_include ? 0 : identifier.start.length;
      let endLen = identifier.end_include ? 0 : identifier.end.length;
      
      //Set up the reference loop
      let textStart = 0;
      let doc = docText;
      let docList = [];
      
      //Loop through text grab the identifier items. Start loop from last set of end identfiers.
      while(textStart > -1){ 
        let textStart = doc.indexOf(identifier.start);
        
        if(textStart === -1){
          break;  
        }else{
          
          let textEnd = doc.indexOf(identifier.end) + identifier.end.length;
          let word = doc.substring(textStart,textEnd);
          
          doc = doc.substring(textEnd);
          
          docList.push(word.substring(startLen,word.length - endLen));
        };
      };
      //return a unique set of identifiers. 
      return [...new Set(docList)];
    };
    
    
    //The "Main" function
    function runsies(){
      const docID = "13TlciLOZV-rxXXXXXXXXXXcGNgCSb7_uXXoZDQ";
      const identifier = {
        start: `ISIN: `,
        start_include: false,
        end: `VERRECHNUNGSKONTO`,
        end_include: false
      };
      let results = getDocItems(docID, identifier);
      //var commaAdd = results.join("''");
      //console.log(results);
      
      const ss = "17a55HCwlO5uF8gXXXXXXXXXXfltlV0UTcHh7vG7A";//The spreadsheet ID
      const sheet = "Stock_Data";//The sheet tab name
      var activeSheet = SpreadsheetApp.getActiveSheet();
      let importToSpredsheet = SpreadsheetApp.openById(ss).getSheetByName(sheet);
      const range = activeSheet.getRange(6,1,results.length,1);
      range.setValue(results);
      //range.sort([2,1]);
    };
____________
      var docFilesId = [];                           //array of files ids from folder
    
      function getListOfId(){
        var folderId = "11tjb_oXXXXXXXXXXY9DViQQJ8u9-g";
        var filesN = DriveApp.getFolderById(folderId).getFiles();
        while (filesN.hasNext()) docFilesId.push(filesN.next().getId());
    }
________
     function moveSheet1() {
          var ss = SpreadsheetApp.getActiveSpreadsheet(); // Selects the spreadsheet
          var ss1 = ss.getSheetByName("Stock_Data"); // Selects Sheet 1
          var data = ss1.getRange(6,1).getValues(); // Gets all values in the sheet
          var ss2 = ss.getSheetByName("Stock_Data2"); // Selects Sheet 2
          var cell = ss.getRange("A6").isBlank();
          if (!cell){
            ss1.getRange(6, 1, ss1.getLastRow() - STOCKDATA_ROW_OFFSET, ss1.getLastColumn()).moveTo(ss1.getRange(7, 1));
          }
        }

const STOCKDATA_ROW_OFFSET = 5

I want the data to be always written to the same cell. That’s why I added the moveSheet1 () function.

If the cell is filled with the data in the first run, it should be moved down one cell in the second run. The data from the second pass should then be written back into the prescribed cell.

At the end of the run, all data are in different cells, one below the other.
1 cell = 1 document.

Perhaps important: I am writing this script in Google Sheets, i.e. Google Apps Script.