Sarthak Gupta
Sarthak Gupta

Reputation: 392

How to import "File upload" module in google form using google-apps-script

I am able to create a small google form using google-apps-script. Which includes texts, radio buttons, etc. But how to include the file upload module using the google-apps-script enter image description here

Sample Code below reads data from the google sheet and creates google form dynamically.

function myFunction() {
try {
    var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
    var range = ss.getDataRange();
    var data = range.getValues();
    var numberRows = range.getNumRows();
    var numberColumns = range.getNumColumns();
    var firstRow = 1;
    var form = FormApp.create(data[0][1])

    for (var i = 1; i < numberRows; i++) {
        var questionType = data[i][0];
        if (questionType == '') {
            continue;
        } else if (questionType == 'TEXT') {
            var getValue = data[i][3];
            form.addTextItem()
                .setTitle(data[i][1])
                .setHelpText(data[i][2])
                .setRequired(getValue);
        } else if (questionType == 'PARAGRAPH') {
            form.addParagraphTextItem()
                .setTitle(data[i][1])
                .setHelpText(data[i][2])
                .setRequired(true);
        } else if (questionType == 'IMAGE') {
            var img = UrlFetchApp.fetch(data[i][6]);
            form.addImageItem()
                .setTitle(data[i][1])
                .setHelpText(data[i][2])
                .setImage(img)
        } else {
            continue;
        }
    }
} catch (error) {
    return error.toString();
}

}

Upvotes: 2

Views: 307

Answers (1)

yuri
yuri

Reputation: 3420

There isn't a method on Forms to include a file upload module using Google Apps Script. I believe this may be a good feature to implement: it may be worth to open a Feature Request on the Google Public Issue Tracker specifying the need of it.

I encourage you to do it because it will help to make possible its implementation.

Google Public Issue Traker: https://issuetracker.google.com/

The tracker for this particular issue is here: https://issuetracker.google.com/issues/64924665

Upvotes: 1

Related Questions