Home > database >  Google Form Responses to Google Slides
Google Form Responses to Google Slides

Time:11-15

I would like to import Google Forms reponses into a Google Slides presentation.

I've already looked at further topics to try to make it on my own, but I have an issue. Here is what I've already built :

`

function onFormSubmit(e) {
  
  var PRESENTATION_ID = "XXXXXXXXXXXX";
  
  var presentation = SlidesApp.openById(PRESENTATION_ID);

  var items = e.response.getItemResponses();

  presentation.replaceAllText('{{Nom}}', items[0].getResponse());
  presentation.replaceAllText('{{Date}}', items[1].getResponse());
  var image = items[2].getResponse();
  presentation.getSlides().forEach(s => {
  s.getShapes().forEach(e => {
    if (e.getText().asString().trim() == '{{Logo}}') {
      e.replaceWithImage(DriveApp.getFileById(Array.isArray(image) ? image[0] : image).getBlob());
    }
  })
})};

`

But the main issue is that, in this case, the data isn't displayed on my Google Slides template (and of course the "XXXXXXXX" present in this code is completed by the real ID of my presentation, but I don't want to share it here).

So here, in this case, the data ins't displayed on my GSlides.

If you have any idea why, I am looking for your help!

Best,

Nonomg

CodePudding user response:

Bind your script with the actual onFormSubmit trigger

This can be done via the Apps Script IDE interface or through the code. For a simple trigger like that, I prefer the first way.

Make sure the updates are pushed to the slides

Normally, as soon as your script ends, Apps Script automatically pushes the modifications to the Slides. If you want to be really sure of that (or if you want to apply the modifications before the script has finished), you can manually call the saveAndClose() method (doc - meaning the Slides is then closed, you cannot do other thing with it unless you re-open it).

Share the Slides with user

On a Presentation, you have a addEditor() method (doc) to share the slides with someone. I'm not sure if it will also send him an email "a presentation has been shared with you". If not, you can use the MailApp service (doc) to easily send an email with the link of the presentation.

CodePudding user response:

Sorry for getting back to you after such a success.

But now, I would like to duplicate my Google Slides presentation and update the duplicated version (because I want to sent it to user).

But unfortunately, I tried this but the duplicated version do not get any modification, and I don't know why :

function onFormSubmit(e) {
  
  var PRESENTATION_ID = DriveApp.getFileById('13-Wce2LrwODBIqEGRLhptOnsb12ECAAGSrnmnGQX4X8');
  
  var newTempFile = PRESENTATION_ID.makeCopy();

  var openSlide = SlidesApp.openById(newTempFile.getId());

  var items = e.response.getItemResponses();

  openSlide.replaceAllText('{{Nom}}', items[0].getResponse());
  openSlide.replaceAllText('{{Date}}', items[1].getResponse());
  var image = items[2].getResponse();
  openSlide.getSlides().forEach(s => {
    s.getShapes().forEach(e => {
      if (e.getText().asString().trim() == '{{Logo}}') {
        e.replaceWithImage(DriveApp.getFileById(Array.isArray(image) ? image[0] : image).getBlob());
      }
    })
  })
  openSlide.saveAndClose();
  DriveApp.getFileById(newTempFile.getId()).setName(items[0].getResponse()   "-"   "InfoMémo");
 }

Do you know why this isn't working ?

Thanks for your help!

  • Related