将 CardService Card 构建器中的所有参数传递给函数
Pass all parameters from CardService Card builder to a function
我已经准备好我的 CardService 卡:
return CardService
.newCardBuilder()
.setHeader(
CardService.newCardHeader()
.setTitle('Elenco operazioni rapide')
.setSubtitle('Inserisci rapidamente gli eventi con questi tasti'))
.addSection(
CardService.newCardSection()
.addWidget(widget)
.addWidget(datatimepickerstart)
.addWidget(datatimepickerend)
.addWidget(button))
.build();
当我按下按钮时:
var action = CardService.newAction()
.setFunctionName('function1')
var button = CardService.newTextButton()
.setText('Calendario')
.setOnClickAction(action)
.setTextButtonStyle(CardService.TextButtonStyle.FILLED);
我想将构建器的所有参数(复选框选择、datatimepickerstart
、datatimepickerend
等)传递给 function1
。我该怎么做?
这是我几年前做过的一个例子:
function buildGetNotesTypesSelectionInput(){
var card=CardService.newCardBuilder();
card.setHeader(CardService.newCardHeader().setTitle('Don\'t Forget - Notes'));
var section=CardService.newCardSection().setHeader('Notes');
var typeSelect=CardService.newSelectionInput()
.setType(CardService.SelectionInputType.DROPDOWN)
.setTitle('Select Note Type')
.setFieldName('Note_Type');//field name
typeSelect.addItem('', '', true);
var optsA=getNoteTypes();
Logger.log('\nselect1 optsA:\n');
for(var i=0;i<optsA.length;i++){
typeSelect.addItem(optsA[i], optsA[i],false);
Logger.log('\noptsA[%s]=%s',i,optsA[i]);
}
//typeSelect.setOnChangeAction(CardService.newAction().setFunctionName('select1Change'));
section.addWidget(typeSelect);
var commentText=CardService.newTextInput()
.setFieldName('Comments')//field name
.setMultiline(true)
.setTitle('Comments');
section.addWidget(commentText);
var action=CardService.newAction().setFunctionName('saveNote');
var saveButton=CardService.newTextButton()
.setText('Save')
.setOnClickAction(action);
section.addWidget(saveButton);
card.addSection(section);
return card.build();
}
以下函数通过字段对象从 cardservice 获取参数
function saveNote(e){
var row=[];
var ts=Utilities.formatDate(new Date(), "America/Denver", "E MMM dd,yyyy HH:mm:ss");
row.push(ts,e.formInput.Note_Type,e.formInput.Comments,Session.getActiveUser().getEmail());//see the fieldnames in this object which is outputting data to a spreadsheet from the addon.
var ss=SpreadsheetApp.openById(gDefault.DontForgetId);
var sh=ss.getSheetByName('Notes');
sh.appendRow(row);
var action=CardService.newAction().setFunctionName('buildGetNotesTypesSelectionInput');
return CardService.newCardBuilder()
.setHeader(CardService.newCardHeader().setTitle('Note Saved'))
.addSection(CardService.newCardSection().addWidget(CardService.newTextParagraph().setText(Utilities.formatString('TimeStamp: %s\nNote Type: %s\nNote: %s\nEmail: %s\n', ts,e.formInput.Note_Type,e.formInput.Comments,Session.getActiveUser().getEmail()))))
.addSection(CardService.newCardSection().addWidget(CardService.newTextButton().setText('Add Another Note').setOnClickAction(action)))
.build();
}
我已经准备好我的 CardService 卡:
return CardService
.newCardBuilder()
.setHeader(
CardService.newCardHeader()
.setTitle('Elenco operazioni rapide')
.setSubtitle('Inserisci rapidamente gli eventi con questi tasti'))
.addSection(
CardService.newCardSection()
.addWidget(widget)
.addWidget(datatimepickerstart)
.addWidget(datatimepickerend)
.addWidget(button))
.build();
当我按下按钮时:
var action = CardService.newAction()
.setFunctionName('function1')
var button = CardService.newTextButton()
.setText('Calendario')
.setOnClickAction(action)
.setTextButtonStyle(CardService.TextButtonStyle.FILLED);
我想将构建器的所有参数(复选框选择、datatimepickerstart
、datatimepickerend
等)传递给 function1
。我该怎么做?
这是我几年前做过的一个例子:
function buildGetNotesTypesSelectionInput(){
var card=CardService.newCardBuilder();
card.setHeader(CardService.newCardHeader().setTitle('Don\'t Forget - Notes'));
var section=CardService.newCardSection().setHeader('Notes');
var typeSelect=CardService.newSelectionInput()
.setType(CardService.SelectionInputType.DROPDOWN)
.setTitle('Select Note Type')
.setFieldName('Note_Type');//field name
typeSelect.addItem('', '', true);
var optsA=getNoteTypes();
Logger.log('\nselect1 optsA:\n');
for(var i=0;i<optsA.length;i++){
typeSelect.addItem(optsA[i], optsA[i],false);
Logger.log('\noptsA[%s]=%s',i,optsA[i]);
}
//typeSelect.setOnChangeAction(CardService.newAction().setFunctionName('select1Change'));
section.addWidget(typeSelect);
var commentText=CardService.newTextInput()
.setFieldName('Comments')//field name
.setMultiline(true)
.setTitle('Comments');
section.addWidget(commentText);
var action=CardService.newAction().setFunctionName('saveNote');
var saveButton=CardService.newTextButton()
.setText('Save')
.setOnClickAction(action);
section.addWidget(saveButton);
card.addSection(section);
return card.build();
}
以下函数通过字段对象从 cardservice 获取参数
function saveNote(e){
var row=[];
var ts=Utilities.formatDate(new Date(), "America/Denver", "E MMM dd,yyyy HH:mm:ss");
row.push(ts,e.formInput.Note_Type,e.formInput.Comments,Session.getActiveUser().getEmail());//see the fieldnames in this object which is outputting data to a spreadsheet from the addon.
var ss=SpreadsheetApp.openById(gDefault.DontForgetId);
var sh=ss.getSheetByName('Notes');
sh.appendRow(row);
var action=CardService.newAction().setFunctionName('buildGetNotesTypesSelectionInput');
return CardService.newCardBuilder()
.setHeader(CardService.newCardHeader().setTitle('Note Saved'))
.addSection(CardService.newCardSection().addWidget(CardService.newTextParagraph().setText(Utilities.formatString('TimeStamp: %s\nNote Type: %s\nNote: %s\nEmail: %s\n', ts,e.formInput.Note_Type,e.formInput.Comments,Session.getActiveUser().getEmail()))))
.addSection(CardService.newCardSection().addWidget(CardService.newTextButton().setText('Add Another Note').setOnClickAction(action)))
.build();
}