i have table, the headers are the project number, the left column is the workers name, i am adding code to start and stop working for each workers in the project. so, when user edit the suitable rectangle it will add new (in or Out) record about that worker and the project.
I have problem with the function called area() , it is not getting the range value from the function onEdit(e).
it is working only when i put the value inside the area() function itself., for example when i put
var vrange = "S10"
or i run it with the fixed value such area("S10")
it is not getting the range variable value when the other functions are getting it correctly
but the range value is dynamic as per the user editing cell.
the problem is happening in this row for only area(range) function, the other functions such getProject(range) is getting the range value correctly.
addRecord(getProject(range),getWorker(range),new Date(),"un",area(range))
hope somebody can know what is my mistake.
here is the code
function onEdit(e) {
var range = e.range
Logger.log("e.range" + range)
var Currentsheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName()
if (Currentsheet == TimeInterface()) {
addRecord(getProject(range), getWorker(range), new Date(), "un", area(range))
}
}
function area(vrange) {
// var frange = "S10"
//var frange = vrange
Logger.log("vrange is " + vrange)
var currentrow = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(vrange).getRow()
var currentcol = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(vrange).getColumn()
var outColumn = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(RecordSettingsSheet()).getRange("B1").getValue()
var recordingFirstColumn = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(RecordSettingsSheet()).getRange("B2").getValue()
var recordingLastColumn = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(RecordSettingsSheet()).getRange("B3").getValue()
var recordingFirstRow = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(RecordSettingsSheet()).getRange("B4").getValue()
var recordingLastRow = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(RecordSettingsSheet()).getRange("B5").getValue()
var answer = ""
if (currentcol == outColumn && currentrow >= recordingFirstRow && currentrow <= recordingLastRow) {
answer = "out"
return answer
} else if (currentrow >= recordingFirstColumn && currentrow <= recordingLastColumn && currentrow >= recordingFirstRow && currentrow <= recordingLastRow) {
answer = "in"
return answer
} else {
answer = "Error"
return answer
}
}
function TimeInterface() {
var TimeInterfacev = "Interface"
return TimeInterfacev
}
function RecordSettingsSheet() {
var recordSettingsSheet = "Record Settings"
return recordSettingsSheet
}
function getProject(range) {
var ProjectID = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(1, range.getColumn()).getValues()
Logger.log("getProject range is " + range)
return ProjectID
}
function getWorker(range) {
var WorkerID = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(range.getRow(), 1).getValues()
return WorkerID
}
function setValue(cellname, Value) {
SpreadsheetApp.getActiveSpreadsheet().getSheetByName(Sheetname()).getRange(cellname).setValue(Value);
}
function getValue(cellname) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName(Sheetname()).getRange(cellname).getValue();
}
function Sheetname() {
var Sheet = "TimeRecords"
return Sheet
}
function newRowNumber() {
var row = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(Sheetname()).getLastRow() + 1;
return row
}
function addRecord(a, b, c, d, e) {
var row = newRowNumber();
var aa = getValue("A" + (row - 1))
var bb = getValue("B" + (row - 1))
var cc = getValue("C" + (row - 1))
var dd = getValue("D" + (row - 1))
if (
a == aa && b == bb && d == dd
) {
} else {
setValue("A" + row, a);
setValue("B" + row, b);
setValue("C" + row, c);
setValue("D" + row, d);
setValue("E" + row, e);
}
}
here is the error detailes
{
insertId: "ofc7bcfvzisc2"
jsonPayload: {
context: {
reportLocation: {
filePath: "Code"
functionName: "area"
lineNumber: 22
}
}
message: "Range not found
at area(Code:22)
at onEdit(Code:12)
"
serviceContext: {
service: "AKfycbyZxuwklLCadxRO93yHKQH0HO34bM9fReTelwt2I39_"
}
}
labels: {
script.googleapis.com/process_id: "EAEA1GOx_xjeztWsGim9PR3gYwydfe6FUt9_U2QNlaA6mIDJNtAm21jdbcWIBqG3z1Hg9CPQuaS_Hf5tJYJh8XqtqDQvgwfh1AX6DQ1M5Jc5tfPEOrgRj7eM4-ueK9m5FidEZBs31l3e-MsG9aHj4JLFEcsntzvvPMZB20Q"
script.googleapis.com/project_key: "MvVaniAhXvNj_E5qpMKyh9JCBc1Z0ol9u"
script.googleapis.com/user_key: "AJw2Yz+oU8zemc1ioio5IJNfc43E3QhuOpzprTTJO/RULzh/3VQSMjron9r4W4J+nuGW9Hj2YCF1"
}
logName: "projects/project-id-5448248979683187508/logs/script.googleapis.com%2Fconsole_logs"
receiveTimestamp: "2018-08-11T15:29:53.172475577Z"
resource: {
labels: {
function_name: "onEdit"
invocation_type: "event"
project_id: "project-id-5448248979683187508"
}
type: "app_script_function"
}
severity: "ERROR"
timestamp: "2018-08-11T15:29:52.164Z"
}
range. getRow()
– tehhowch