Hello community, I need one help
How can I set an Action inside AppSheet to Create a Copy from Google Slides Template and automatically rename the file and save in specific Google Drive Folder?
I can easily do it in Google Apps Scriptโฆ the user just click a button and all of that is done and it opens the Copied and Renamed presentation.
Thank you
Solved! Go to Solution.
@Caio
You can find the GAS function below. However, you need to tailor the code, the slide template and other variable as per your requirements. This function is called via doPost(e) from the webhook. CERT_TEMP_ID is a global variable pointing out to the file ID of the Google Slide template and FOLDER_ID is a global variable pointing out the resulting folder in Google Drive.
function generate5S_Certificate(trndate, surucu, egitmen, sertifikaText, puan, egitmenImzaID) {
try {
if ((puan !== "" || puan !== null)) {
var tempName = UUID();
var tempSlide = DriveApp.getFileById(CERT_TEMP_ID).makeCopy(tempName, DriveApp.getFolderById(FOLDER_ID));
var tempSlideID = tempSlide.getId();
//FILL CERTIFICATE FIELDS WITH DATA IN SLIDE
var presentation = SlidesApp.openById(tempSlideID);
var slide = presentation.getSlides()[0];
var shapes = slide.getShapes();
shapes[6].getFill().setTransparent();
shapes[7].getFill().setTransparent();
shapes[8].getFill().setTransparent();
shapes[4].getText().setText(sertifikaText);
shapes[5].getText().setText(surucu);
shapes[9].getText().setText(puan);
if (egitmen == "Zafer AKรAY" || egitmen == "Fulya AKรAY") {
shapes[12].getText().clear();
if (typeof slide.getImages()[6] !== 'undefined') {
slide.getImages()[6].remove();
}
} else {
shapes[12].getText().setText(egitmen+"\nAdvanced Instructor");
if (typeof slide.getImages()[6] !== 'undefined') {
slide.getImages()[6].remove();
}
var image = DriveApp.getFileById(egitmenImzaID);
var position = {left: 390, top: 445};
var size = {width: 136, height: 64};
slide.insertImage(image, position.left, position.top, size.width, size.height);
}
var point = +puan;
if (point >= 20 && point <= 24) {
shapes[6].getFill().setSolidFill('#000000');
shapes[7].getFill().setSolidFill('#000000');
shapes[8].getFill().setSolidFill('#000000');
} else if (point >= 25 && point <= 38) {
shapes[6].getFill().setSolidFill('#000000');
shapes[7].getFill().setSolidFill('#000000');
} else if (point >= 39 && point <= 49) {
shapes[6].getFill().setSolidFill('#000000');
}
presentation.saveAndClose();
//GENERATE A PDF OF THE CERTIFICATE
var blob = DriveApp.getFileById(tempSlideID).getBlob().getAs("application/pdf");
var fsurucu = surucu.replace(/[\u00DC]+/g,"U").replace(/[\u011E]+/g,"G").replace(/[\u0130]+/g,"I").replace(/[\u00D6]+/g,"O").replace(/[\u00C7]+/g,"C").replace(/[\u015E]+/g,"S");
var filename = fsurucu+"_KB_"+constructReportDate(trndate)+".pdf"
var certificate = DriveApp.getFolderById("1IkOZx5kV_VeQgdH_1aoc5_p2Tb_kjY5E").createFile(blob).setName(filename);
DriveApp.getFileById(tempSlideID).setTrashed(true);
return certificate
}
} catch (e) {
MailApp.sendEmail("levent@able3ventures.com", "5S Scripting Error Occured!",
"\r\nMessage: " + e.message
+ "\r\nFile: " + e.fileName
+ "\r\nLine: " + e.lineNumber);
}
}
User | Count |
---|---|
18 | |
9 | |
8 | |
5 | |
5 |