Apply filter with variable as dynamic data [app script]

I’m on a project in which I get stuck just on the final step.

let me explain:
my project to filter data and move the filtered data to another spreadsheet (by the way if you see this Marios thanks a lot for your help). all work properly without issues but something happened and the issue is that I need to input dynamic data as filter and sheet name. I created 2 variables location which will determine the filter and fromApp which will determine the sheet name.

my goal is to send the data through the web with its tag to be filtered in the desired sheet.

FYI: the app script is bound to a gsheet.

Here is the code:

function doGet(e) {
    return querySheet(e);
  }
  
  function doPost(e) {
    return querySheet(e);
  }
  
  **function tagValue(e) {
    var location = e.parameter.location ; // send from app with respective tag
    var fromApp = e.parameter.fromApp ; // send from app with respective tag**
  
  }
  
  function FilterOnText() {
     var ss = SpreadsheetApp.getActive()
     var range = ss.getDataRange();
     var filter = range.getFilter() || range.createFilter()
     var text = SpreadsheetApp.newFilterCriteria().whenTextContains(location); // the location will be as per the location variable in the tagValue function
     filter.setColumnFilterCriteria(1, text);
  }
  
  function titleAsDate() { 
    const currentDate = Utilities.formatDate(new Date(), "GMT+8", "dd-MM-yyyy HH:mm:ss");
    return SpreadsheetApp.create("Report of the " + currentDate);
  }
  
  function copyWithValues() { 
    const spreadSheet = SpreadsheetApp.getActiveSpreadsheet();
    const sourceSheet = spreadSheet.getSheetByName('fromApp'); // fromApp variable will define which sheet the data will be copied (situated in the tagValue function)
    const temp_sheet = spreadSheet.insertSheet('temp_sheet');
    const sourceRange = sourceSheet.getFilter().getRange();
    sourceRange.copyTo(
      temp_sheet.getRange('A1'),
      SpreadsheetApp.CopyPasteType.PASTE_NORMAL,
      false);
    SpreadsheetApp.flush();
    
    const sourceValues = temp_sheet.getDataRange().getValues();
    
    const targetSpreadsheet = titleAsDate();
    
    const rowCount = sourceValues.length;
    const columnCount = sourceValues[0].length;
    
    const targetSheet = targetSpreadsheet.getSheetByName('Sheet1').setName("Report"); // renamed sheet
    const targetRange = targetSheet.getRange(1, 1, rowCount, columnCount);
    targetRange.setValues(sourceValues);
    spreadSheet.deleteSheet(temp_sheet);
  }
1 Like