'Creating installable trigger in a spreadsheet using custom library - google app script
I have a stand alone library script that contains functions to create an installable onEdit trigger.
The idea is to use this library in a bound script of a new spreadsheet to create an installable trigger native to the new spreadsheet.
So far I have ensure the library is shared to "Anyone with link can access", I've added the library to the new spreadsheet bound script and it seems to have access to all the library functions.
I can execute the function to create the trigger but the trigger continuously fails with the error "Script function not found: onEditTrigger".
The library code that seems to be causing the issue is contained in the createOnEditTrigger function. Theoretically the createOnEditTrigger function should be called from the bound script once after adding the library:
var onEditTriggerID = ScriptApp.newTrigger("onEditTrigger")
.forSpreadsheet(ssID)
.onEdit()
.create()
.getUniqueId();
The onEditTrigger function that is referred to in the error is also within the same library. It takes in the event parameter and uses the range and value to determine other functions to execute within the same library:
function onEditTrigger(e)
{
var range = e.range;
var value = e.value;
var row = range.getRow();
var col = range.getColumn();
var ssObj = e.source;
var spreadsheetID = ssObj.getId();
// training Plan Ranges that can be edited
var exerciseCheckboxRanges = ["A11","A14","A21", "A24","A28","A31","A35", "A38", "A42"];
var exerciseLoadRanges = ["R10","R13","R20", "R23","R27","R30","R34", "R37", "R41"];
var rateWorkoutRange = "S44";
var trainingPlanSheet = ssObj.getSheetByName("Training Plan");
var trainingPlanData = trainingPlanSheet.getDataRange().getValues();
var workoutCompleteIndex = indexOf2d(trainingPlanData,"Workout Completed");
var workoutCompleteRow = workoutCompleteIndex[0] + 1;
var workoutCompleteRange = "I" + workoutCompleteRow;
if(exerciseCheckboxRanges.includes(range.getA1Notation()))
{
// exercise checkboxes
exerciseCheckboxTrigger(spreadsheetID, value, range);
}
if(exerciseLoadRanges.includes(range.getA1Notation()))
{
exerciseLoadTrigger(spreadsheetID,value, range.getA1Notation());
}
if(range.getA1Notation() == workoutCompleteRange)
{
if(value)
{
var ui = SpreadsheetApp.getUi();
var response = ui.alert('This will move you onto the next session, are you sure you want to continue?', ui.ButtonSet.YES_NO);
// Process the user's response.
if (response == ui.Button.YES)
{
completeWorkoutTrigger(spreadsheetID,value,range.getA1Notation());
}
else
{
return;
}
}
}
}
Can anybody provide any insight into why this is happening?
I should note that I can create the trigger fine and it works exactly as expected if the createOnEditFunction is executed from the original standalone library script and not from using the library in the bound script. However the trigger is created in the original library script and not the bound script which is not ideal.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
