google-apps-scriptgoogle-apps-for-education

Embed a list of forms in Google Site per DocList


I used the code given in Embedding Google DocList in a Google Site to embed a list of files (taken from a folder in Google drive) in a page of Google Sites. I like to know, if there's a way to modify the links on the output-page, so that they direct to the live-form of the spreadsheet and not to the spreadsheet-mode as it's set in the script.


Solution

  • EDIT : sorry about that, forget this first answer as there is actually a method to get form urls !!

    here is how it works

    function myFunction() {
      var ss=SpreadsheetApp.getActive()
      var formurl = ss.getFormUrl()
      Browser.msgBox(formurl)
    }
    

    so it would be quite easy to embed a list in a site page,

    here is a small code that does the job, online version here (needs authorization) be patient : can be slow to show up...

    function doGet() {
      var app=UiApp.createApplication().setTitle('Available Forms').setStyleAttribute('padding', '25');
      var user = Session.getEffectiveUser().getUserLoginId();
      app.add(app.createLabel('Available forms in Drive for '+user).setStyleAttribute('background', '#dddd33').setPixelSize(500, 18).setHorizontalAlignment(UiApp.HorizontalAlignment.CENTER).setStyleAttribute('fontWeight', 'bold'))
      var flex=app.createFlexTable().setId('flex').setWidth('500').setBorderWidth(1).setCellPadding(2).setStyleAttribute('borderColor', '#dddd33');
      var index = 0
      var docs = DocsList.getAllFiles()
        for (var n in docs){
          if(docs[n].getFileType()=="spreadsheet"){
            var ss=SpreadsheetApp.openById(docs[n].getId())
             if(ss.getFormUrl()){
        flex.setText(index, 0, docs[n].getName())
        flex.setWidget(index, 1, app.createAnchor('open form', ss.getFormUrl()))
        ++ index
      }
      }
      }
      app.add(flex)
      return app
    }
    

    again sorry that I forgot this feature.


    -Forms are embedded in spreadsheet and don't appear as individual entities in your drive. Their ID (or URL) are not available from apps-script.... I'm afraid you'll have to encode the URLs manually.-