Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 使用脚本在非根文件夹中创建表单_Google Apps Script_Google Forms - Fatal编程技术网

Google apps script 使用脚本在非根文件夹中创建表单

Google apps script 使用脚本在非根文件夹中创建表单,google-apps-script,google-forms,Google Apps Script,Google Forms,我正在尝试编写一个脚本,将电子表格列标题转换为表单中的问题。我希望能够在电子表格所在的文件夹中运行此脚本,并让它在同一文件夹中创建表单。问题是,无论我把脚本放在哪里,表单都会在根文件夹中创建。我在表单和FormApp文档中没有找到任何帮助。我敢肯定这只是函数调用的一个简单修改,但是 function createForm() { // Create a new form, then add a checkbox question, a multiple choice question, //

我正在尝试编写一个脚本,将电子表格列标题转换为表单中的问题。我希望能够在电子表格所在的文件夹中运行此脚本,并让它在同一文件夹中创建表单。问题是,无论我把脚本放在哪里,表单都会在根文件夹中创建。我在表单和FormApp文档中没有找到任何帮助。我敢肯定这只是函数调用的一个简单修改,但是

function createForm()
{
  // Create a new form, then add a checkbox question, a multiple choice question,
// a page break, then a date question and a grid of questions.
var form = FormApp.create('New Form');
var form = FormApp.create('Form Name');
var item = form.addCheckboxItem();
item.setTitle('This is a bunch of gibberish!!!!!!!!!!!!');
item.setChoices([
        item.createChoice('Relish')
    ]);
Logger.log('Published URL: ' + form.getPublishedUrl());
Logger.log('Editor URL: ' + form.getEditUrl());
}

快速而肮脏的解决方案如下:

function createForm(){
//get the form file through id of the form you just made
var form     = FormApp.create('tempForm'),
    id       = form.getId(),
    formFile =  DriveApp.getFileById(id);
//get the id of the folder you want to move the form to
var folderId   = DriveApp.getFolderById('folderID');
//delete the temporary form
formFile.setTrashed(true);
//copy the temp form (still active) to the destination folder, open it.
var newId    = formFile.makeCopy(folder).setName('myCopiedForm').getId(),
    form     = FormApp.openById(newId);
}
它很脏,但能用。如果有更好的解决方案,请告诉我