Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
Is there a way to check if a next event includes a term in the title?

I have made a script that updates events title after an user submits a form, based on this condition:

for(var j=0; j<events.length;j++){
        var ev = events[j];
        if(!ev.getTitle().includes("Returned"){ ...

I want the script to check if there is one or many events that include the term "Returned", but only among the next events.

For example, the condition should be false if an event title does not include "Returned" AND none of the next events titles include "Returned".

Is that possible? I tried with creating a variable evnext = events[j+1] but of course I get an error once it gets to the last event.

Thank you for your help, I feel it is very doable but my understanding of loops is sadly too low ...

Edit: details on my goal

Actually my script sends an email to all people who borrowed an equipment but did not confirm they returned it.

The problem now is that I would like to send an email to these people EXCEPT IF someone else returned it afterwards.

It would indeed mean that even the first borrower did not confirm he returned it, the fact that someone who took it next and marked it as returns proves that the first person actually returned the equipment.

Otherwise it would not have been possible for the next guy to return it.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can try the following script:

function listEvents()
{
  let calendar = CalendarApp.getCalendarById("Calendar ID"); // Change the calendar ID
  var today = new Date();
  for(let i=1; i<=30; i++) // 30 days limit
  {
    var events = calendar.getEventsForDay(today, {search: 'Returned'});
    if(events.length != 0)
    {
      MailApp.sendEmail("email@domain.com","Subject","Body");
    }
    today.setDate(today.getDate() + 1);
  }
}

In this example the script takes the current date and starts checking day by day of a specific calendar for the upcoming 30 days if an event has the word "Returned" on its title and returns False if not.

Let me know if this helps. I can also modify the script if needed. You can modify the 30 days limit, and the initial date depending on your needs. Do not forget to change the calendar ID to the one you are currently using to save the events.

References:

  • getEventsForDay(date, options)
about 4 years ago · Juan Pablo Isaza Report

0

How about this:

for(var j=0; j<events.length;j++){
        var ev = events[j];
        if(j < events.length - 1) {
          if(ev.getTitle().include("Returned") && events[j+1].include("Returned")) {}
        } else {
          if(!ev.getTitle().includes("Returned") {}
        }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!