let has a more limited scope than
var, but you are not using
let… so could it be that your
if condition is not being met to create the variable?
Maybe try console logging something when the condition is met to ensure your variable should be created. But also consider your logic for what you have. If there is any chance you are not creating a variable, you should never try to reference it.
Somehow in the version on github, I had var, but in Scriptable I had let. It works now.
Now, next question:
Is there a function in Scriptable to end the script. So if a user selects Cancel in my script, the script ends? Or is that going to require reworking my whole script into an if statement?
But also consider restructuring too.
Also, github has been updated if anyone else wants to use this script. I just don’t have a contingency in place for if the user cancels the action. Currently, the script creates a group with a blank title and no contacts if the user cancels.
I just noticed an answer to my question in this thread right next to mine.
This place is the best. Script update coming soon.
If you want, you could do
const group = allGroups.find(group => group.name === userGroup). That will return the group if it finds a match, or it will return
null if no match is found. It simplifies the code to a single line too