I'm working on an automation which takes an info table from a control sheet and iterates the info table values into a template to print a pdf for each iteration.
To print the selected ranges I've used this code posted here on 2019 which works perfectly when I call the function on line 36.
Now I'm trying to save each pdf based on the parameters of each iteration into a specific folder ("FOM") located in Drive.
I'm wondering if I could set some input parameters to this referenced function like folder and file name.
var folder = DriveApp.getFoldersByName('FOM'); //Google Drive Folder
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var fom = spreadsheet.getSheetByName("6"); //Template Sheet
fom.activate();
var part_input = fom.getRange("B7"); //Location for part name
var id_input = fom.getRange("E7"); //Location for part id
var asm_input = fom.getRange("K7"); //Location for assembly name
var asm_id = fom.getRange("N7"); //Location for assembly id
var control = spreadsheet.getSheetByName("3"); //control sheet
control.activate();
var parts = control.getRange("B38:B44").getValues(); //Info table names
var ids = control.getRange("D38:E44").getValues(); //Info table ids
function FOMprint() {
for(var r=0;r<parts.length;r++){ //Info table row
for(var c=0;c<ids[0].length;c++){ //Info table column
fom.activate();
if(parts[r] =='Tanque 12L'){ //Check if assembly based on name
spreadsheet.getRange("K3:P38").activate();
asm_input.setValue(parts[r]);
asm_id.setValue(ids[r][c]);
}
else{
spreadsheet.getRange("B3:G44").activate();
part_input.setValue(parts[r]);
id_input.setValue(ids[r][c]);
}
printSelectedRange(); //print function as refered above
}
}
};
Any suggestion is welcomed since this is my first code on google sheets.