我有一个Google表单,其中提出了一个问题,“是否已创建了传单”,如果答案为“否”,那么我需要从表单提交中收集某些数据并在一个新行中插入一个新行。外页。 I have a drawing here.
表#1(the sheet with the form is here) 第2页(sheet that will get a new conditional row submit is here)
我已经启动了一个脚本来执行此插入,但我没有完成脚本的知识。
function onFormSubmit(e) {
var timestamp = e.values[0];
var name = e.values[1];
var phone = e.values[2];
var classTitle = e.values[4];
var dueDate = e.values[7];
//when there is field 19 in this sheet answer is No (There has not yet been a flyer created) this is when the insert would happen and the Field 19 answer is not something that needs to be carried to the new row in the external sheet)
var formCreated = e.values[19];
var workType = "Flyer" ;
var contextNote = "This job was imported from a Org Learning's Class Reservation Form and followup will be required for clarification" ;
var destinationSpreadSheetKey = "0Ai_2YLvaQba0dHA2bTdtd0pnTTZQcnRldjJXcjFjZHc";
var destinationSheet = "Work_Orders";
//if the answer to variable formCreated is "Yes", then halt Else continue with script
有人会帮我这个剧本吗?我有一张图中字段的地图。
谢谢,
戴夫
答案 0 :(得分:1)
最终的工作代码,评论很好。
/**
* Copies from separate source ranges and pastes at first empty row on target sheet
*/
function CopyIt() {
var source_spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var target_spreadsheet = SpreadsheetApp.openById("0Ai_2YLvaQba0dHA2bTdtd0pnTTZQcnRldjJXcjFjZHc");
// Get source and target sheets - can be the same or different
var sourcesheet = source_spreadsheet.getSheetByName("Form Responses");
var targetsheet = target_spreadsheet.getSheetByName("Work_Orders");
//Get row of last form submission
var source_last_row = sourcesheet.getLastRow();
// Check for answer to Flyer Created? If Yes, end now. If not Yes, i.e. No, continue.
var check = sourcesheet.getRange("T" + (source_last_row)).getValue();
if (check != 'Yes') {
// Get the source ranges
// TimeStamp
var source_range1 = sourcesheet.getRange("A" + (source_last_row));
//Name
var source_range2 = sourcesheet.getRange("B" + (source_last_row));
//Phone Number
var source_range3 = sourcesheet.getRange("C" + (source_last_row));
//Class Name/Title
var source_range4 = sourcesheet.getRange("E" + (source_last_row));
//First Session
var source_range5 = sourcesheet.getRange("H" + (source_last_row));
var source_range1_values = source_range1.getValues();
var source_range2_values = source_range2.getValues();
var source_range3_values = source_range3.getValues();
var source_range4_values = source_range4.getValues();
var source_range5_values = source_range5.getValues();
// Get the last row on the target sheet
var last_row = targetsheet.getLastRow();
// Set the target ranges on target sheet
//TimeStamp
var target1 = targetsheet.getRange("A" + (last_row + 1));
//Name
var target2 = targetsheet.getRange("H" + (last_row + 1));
//Phone
var target3 = targetsheet.getRange("I" + (last_row + 1));
//Your Project Name
var target4 = targetsheet.getRange("K" + (last_row + 1));
//Final Due Date
var target5 = targetsheet.getRange("M" + (last_row + 1));
//The next two are defined in script
var target6 = targetsheet.getRange("O" + (last_row + 1));
var target7 = targetsheet.getRange("Q" + (last_row + 1));
// Put the data from the source sheet into the target sheet, after adding a new row
targetsheet.insertRowAfter(last_row);
target1.setValues(source_range1_values);
target2.setValues(source_range2_values);
target3.setValues(source_range3_values);
target4.setValues(source_range4_values);
target5.setValues(source_range5_values);
// Just using the text to put this data, so there is no source range above.
target6.setValue('Flyer');
target7.setValue('This job was imported from a Org Learning\'s Class Reservation Form and followup will be required for clarification');
}
}