Click here to Skip to main content
15,886,783 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.



What I have tried:

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);
}
Posted
Comments
20212a 19-Feb-21 11:17am    
What is your question?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900