-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyncForm.gs
More file actions
65 lines (53 loc) · 2.12 KB
/
Copy pathsyncForm.gs
File metadata and controls
65 lines (53 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//----------------------------------------------------
//フォーム同期プログラム
//#カテゴリ名の本の配列を取得
function getCategoryArray(category){
//カテゴリ名のシートを取得
var sheet = ss.getSheetByName(category);
// A行の2行目からコンテンツをもつ最後の行までの値を配列で取得する
var categoryArray = sheet.getRange(3,2,sheet.getLastRow() - 2).getValues();
Logger.log(categoryArray);
return categoryArray;
}
//#フォームの選択肢にカテゴリ別の本をぶち込む
function overwriteList(category,categoryArray) {
/**
// Googleフォームのプルダウン内の値を上書きする
//
**/
// GoogleフォームのIDを設定 →「https://docs.google.com/forms/d/〇〇〇/edit」の〇〇〇を↓に記述
var form = FormApp.openById('1QHUgJYF-13DBRR_PHrfTzeJxIAJvL2_yIQsyweE9UU8');
// 質問項目がプルダウンのもののみ取得
var items = form.getItems(FormApp.ItemType.LIST);
items.forEach(function(item){
// 質問項目が「好きなDJを選択して下さい」を含むものに対して、スプレッドシートの内容を反映する
if(item.getTitle().match(category)){
var listItemQuestion = item.asListItem();
var choices = [];
categoryArray.forEach(function(name){
if(name != ""){
choices.push(listItemQuestion.createChoice(name));
}
});
// プルダウンの選択肢を上書きする
listItemQuestion.setChoices(choices);
}
});
}
//#一斉同期
function sync(){
//カテゴリー一覧を取得
var glanceSheet = ss.getSheetByName('使い方&貸出者一覧');
var categorys = glanceSheet.getRange(7,2,1,glanceSheet.getLastColumn() - 1).getValues()[0];
//Logger.log(categorys);
//Logger.log(categorys.length);
//カテゴリー別の本のリストを作成
var categorysArrays = [];
for(i = 0;i < categorys.length;i++){
categorysArrays.push(getCategoryArray(categorys[i]));
}
//Logger.log(categorysArrays);
for(i = 0;i < categorysArrays.length;i++){
overwriteList(categorys[i],categorysArrays[i]);
}
}