I recently created a script that updates event titles once a user submits a form based on a specific condition:
for(var j=0; j<events.length;j++){
var ev = events[j];
if(!ev.getTitle().includes("Returned"){ ...
My goal is for the script to check if any of the upcoming events have the term "Returned" in their titles. However, I want it to only consider events following the current one.
For instance, the condition should return false if an event title doesn't have "Returned" in it and none of the subsequent event titles contain "Returned" either.
Is there a way to achieve this? I attempted to create a variable evnext = events[j+1]
, but it throws an error when it reaches the last event.
Any guidance would be greatly appreciated. I believe this is achievable, but my understanding of loops is holding me back.
Edit: clarification on my objective
Essentially, my script sends emails to individuals who borrowed equipment but didn't confirm its return. The issue arises when I want to exclude individuals who didn't confirm the return, but someone else returned the equipment afterwards.
This scenario suggests that even if the initial borrower didn't confirm the return, the subsequent borrower's confirmation implies that the equipment was indeed returned by the first person. Otherwise, the second borrower wouldn't have been able to return it.