메뉴 건너뛰기

app

[GAS] 설문지가 여러개 있는 시트이름 확인 및 동적 폼 셀렉트 리스트

lispro062015.12.27 16:42조회 수 1570댓글 0

    • 글자 크기
function onFormSubmit(e) {
  var sheet = e.range.getSheet();
  var sheetName = sheet.getSheetName();
  var sheetId = sheet.getSheetId();
}

시트 이름이나 아이디를 확인해 설문지 제출시 트리거를 사용할 수 있다.
a 설문지에 의해 a 시트가 업데이트 되면 afunction을 동작하도록 할 수 있는 것이다.


아래는 폼에서 셀렉트 리스트를 동적 업데이트 하는 코드이다.

불필요 배열 값 제거 함수들도 포함 되었다.

function removeArrayDuplicate(array) {
var a = {};
for(var i=0; i <array.length; i++){
if(typeof a[array[i]] == "undefined")
a[array[i]] = 1;
}
array.length = 0;
for(var i in a)
array[array.length] = i;
return array;
}
function cleanArray(actual){
  var newArray = new Array();
  for(var i = 0; i<actual.length; i++){
      if (actual[i]){
        newArray.push(actual[i]);
    }
  }
  return newArray;
}
function doGet() {
  var ss = SpreadsheetApp.openById("문서명");
  
  var _code_ = ss.getSheetByName('_CODE_');
  var teams = _code_.getRange(2, 3, _code_.getLastRow(), 1).getValues();
  var officer = _code_.getRange(2, 2, _code_.getLastRow(), 1).getValues();
  var job = _code_.getRange(2, 1, _code_.getLastRow(), 1).getValues();
  
  var form = FormApp.openById('폼이름');
  var item1 = form.addListItem();
  for(i=form.getItems().length-2;i>-1;i--){
    form.deleteItem(i);// 일단 폼 아이템들을 모두 지워버리고 다시 만든다. 개별 리스트를 지우고 업데이트할 수도 있지만, 효율적이지 않을 때가 있다. 
  }
  
  item1.setTitle('제목1').setChoiceValues(removeArrayDuplicate(teams));
  var item2 = form.addListItem();
  item2.setTitle('제목2').setChoiceValues(removeArrayDuplicate(officer));
  var item3 = form.addListItem();
  item3.setTitle('제목3').setChoiceValues(removeArrayDuplicate(job));
  var item4 = form.addTextItem();
  item4.setTitle('제목4');
  var item5 = form.addTextItem();
  item5.setTitle('제목5');
}
lispro06 (비회원)
    • 글자 크기
[GAS] 구글 앱스 계정에서 JSONP 사용 (by lispro06) [안드로이드] 크롬 adb plugin (by lispro06)

댓글 달기

suritam9
2021.12.15 조회 320
suritam9
2019.04.05 조회 2067
suritam9
2019.03.07 조회 311
suritam9
2019.03.06 조회 749
lispro06
2018.03.21 조회 855
lispro06
2018.03.16 조회 1955
lispro06
2017.11.27 조회 6512
lispro06
2017.07.16 조회 1736
lispro06
2017.06.22 조회 1931
lispro06
2016.11.02 조회 1712
lispro06
2016.11.01 조회 7492
lispro06
2016.10.27 조회 4210
lispro06
2016.10.27 조회 3008
lispro06
2016.10.27 조회 4007
lispro06
2016.10.27 조회 2667
lispro06
2015.11.20 조회 1627
첨부 (0)
위로