I have 2 sheets within my spreadsheet per the following link:
The first, called "Events/Incidents" records all event data ranging from complaints, compliments, accidents and near misses. If there is an event requiring an insurance claim, the user will tick the box in column Y which will require another user to file the claim. I have therefore created the second sheet titled "Insurance Claims". This will be like a Gantt chart timetabling progress on the insurance claim.
Once the initial user ticks the box in column Y of the "Events/Incidents" I want values from a number of cells from the corresponding row to be copied and pasted into the "Insurance Claims sheet.
I am still learning to write code so I tend to pinch code from other Stack Overflow answers but I am struggling with this one. Here is my current attempt but I feel like I am missing critical parts to the function.
//Data from Events/Incidents Sheet to Insurance Claims Sheet
function dataInsuranceClaimsSheet() {
// setup spreadsheet and sheets
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sourcesheetname = "Events/Incidents";
var source = spreadsheet.getSheetByName(sourcesheetname);
var targetsheetname = "Insurance Claims";
var target = spreadsheet.getSheetByName(targetsheetname);
var trigger = source.getRange(3, 1, 1, 25) //column Y of Events/Incidents sheet
// get Form Response
//Logger.log(JSON.stringify());
var row = source.range.getRow();
var range = source.getRange(row, 1, 1, 26);
//Logger.log("DEBUG: The range is "+range.getA1Notation());
var values = range.getValues();
var sourceDate = values[0][1]
var sourceId = values[0][2];
var sourceBranch = values[0][3];
var sourceEmployee = values[0][5]
var sourceFleet = values[0][7];
var sourceRoute = values[0][8];
var sourceDescription = values[0][17]
var targetDate = values[0][1]
var targetId = values[0][2];
var targetBranch = values[0][3];
var targetEmployee = values[0][4]
var targetFleet = values[0][5];
var targetRoute = values[0][6];
var targetDescription = values[0][7]
//update the Insurance Claims sheet
var targetupdate = [];
var targetfinal=[];
// push the values to a blank array
targetupdate.push(sourceDate); // Date
targetupdate.push(sourceId); // ID
targetupdate.push(sourceBranch);// Branch
targetupdate.push(sourceEmployee); // Employee
targetupdate.push(sourceFleet); // Fleet
targetupdate.push(SourceRoute);// Route
targetupdate.push(sourceDescription);// Description
// if column Y of the Events/Incidents sheet = TRUE then copy the data from the Events/Incidents sheet and paste into the defined cells of the Insurance Claims sheet
if (trigger == TRUE);
targetfinal.push(targetupdate);
// get Insurance Claims data
var targetLR = target.getLastRow();
var targetupdaterange = target.getRange(targetLR+1,1,1,8);
Logger.log("DEBUG: The target range = "+targetupdaterange.getA1Notation());
// update the form values to the Insurance Claims sheet
targetupdaterange.setValues(targetfinal);
}
I would really appreciate some help with this one.
var row = source.range.getRow();Your comment says// get Form Response. What kind of Form are you referring to? - Cooper