LoginSignup
2
0

More than 3 years have passed since last update.

すでに回答がなされたGoogleFormを作成する

Posted at

すでに回答がなされたGoogleFormを作成する

URLを押したら回答の初期値が記入されてるリンクが欲しい
よくあるでしょう
最近安直に記事を書くことにしたのでとりあえずかきます

今回使ったもの

-Google App Script 
-Google Form

全容

単純なフォームを作ってスクリプトを開きます

実行前

実行後

スクリプト全容
function myFunction() {
  var form = FormApp.getActiveForm();
  var item = form.getItems()[0].asTextItem();
  var item_response = item.createResponse("hello");
  var create_response = form.createResponse();
  console.log(create_response.withItemResponse(item_response).toPrefilledUrl());
  // ->https://docs.google.com/forms/d/e/<formID>/viewform?usp=pp_url&entry.<ID>=hello
}

ログに出てきたものを開くとなります.
いろんなサイトを見ると検証からフォームの回答欄のIDを調べるとかいろいろありますが,GASでまわすとなるとこんな感じで後はうまくやればできそうですね

まとめ

半年前,めっちゃ調べたけど無理だったのに...
ちゃんと公式APIをみるべきらしい
いろいろ見たけどGoogleAppScriptAPI見やすすぎる

参考リンク

GAS公式( .withItemResponse(response) )

Formにスクリプトからsubmitする (Google Apps Script試行錯誤 Blog Google)

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0