Is there a method to determine if a future event has a specific term in its title?

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.

Answer №1

Check out this snippet:

for(let i=0; i<dataArray.length;i++){
        let item = dataArray[i];
        if(i < dataArray.length - 1) {
          if(item.getName().includes("Returned") && dataArray[i+1].includes("Returned")) {}
        } else {
          if(!item.getName().includes("Returned")) {}
        }

Answer №2

If you want to automate event tracking, consider using the script below:

function checkEvents()
{
  let calendar = CalendarApp.getCalendarById("Insert Calendar ID Here"); // Update the calendar ID
  var today = new Date();
  for(let i=1; i<=30; i++) // Set a 30-day limit
  {
    var events = calendar.getEventsForDay(today, {search: 'Returned'});
    if(events.length != 0)
    {
      MailApp.sendEmail("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e88d85898184a88c8785898186c68b8785">[email protected]</a>","Subject","Body");
    }
    today.setDate(today.getDate() + 1);
  }
}

This script checks a specific calendar for events with the word "Returned" in the title for the next 30 days, returning False if none are found.

Feel free to reach out if you need any adjustments to the script. You can customize the number of days or the starting date based on your requirements. Remember to update the calendar ID to match the one you're using for event tracking.

For more information, you can refer to:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Power of Asynchronous Programming with Node.js and Typescript's Async

I need to obtain an authentication token from an API and then save that token for use in future API calls. This code snippet is used to fetch the token: const getToken = async (): Promise<string | void> => { const response = await fetch(&apos ...

Tips for implementing orderBy and filter in ng-repeat when working with an object instead of an array

I am facing a data structure that looks like this: $scope.people = { "ID123": { name_de: "Andre", name_en: "Anrew", age: 30, description: "He is the father of xyz and . . .", . . . ...

Utilize the Material UI SelectField component as a reference for handling onChange events

I'm facing a challenge with my form that contains over 15 SelectField components. I want to avoid creating multiple change handler functions, but I can't figure out how to identify the specific select field that triggered the change event in orde ...

Monitoring multiple items in OPC UA with Node.js

Utilizing the node-opcua module, my goal is to efficiently monitor multiple opc ua nodes through subscriptions. The desired workflow involves a user selecting nodes in an HTML UI, clicking a Monitor button which then sends the corresponding nodeIds as para ...

Confirmation message for deletion using jQuery on dynamic elements

My div is populated with dynamically added records. Whenever I click on the 'Remove' link, a confirmation box pops up multiple times corresponding to the number of records present in the div. I want the confirmation box to appear only for the spe ...

The collapsed feature of the Bootstrap 4 Navbar is not functioning as

Recently, I delved into the world of Bootstrap 4 and decided to create a collapsing menu. Everything seemed to be working fine when I clicked the button and saw the content display perfectly. However, things took a turn for the worse when I tried to collap ...

NodeJS: Retrieve Over 10,000 Images From the Server

Attempting to retrieve over 10,000 images from a server led me to create this script: const http = require('http') const fs = require('fs') const opt = { agent: new http.Agent({ keepAlive: true, maxSockets: 5 }), headers ...

Utilizing Angular's Scope Functionality

I am a novice in the world of AngularJS. Currently, I am delving into the expert's codebase and looking to customize the directives for educational purposes. Interestingly, the expert consistently includes: this.scope = $scope; at the start of eac ...

Anomalous Link Behavior on iOS

I am encountering a strange issue with links on the provided website in iOS: When I try to tap on the links under the "Galleries" menu, such as "Benny," nothing happens. It appears that Safari is trying to load the new page, but then it fails to do so. H ...

Load annotations from a JSON file with Annotator.js

Seeking assistance with incorporating annotations into my website using annotator.js. I have been encountering difficulties getting it up and running successfully. My goal is to display highlighted annotations upon page load, but I keep receiving a JavaSc ...

What is the best way to attach several URLs to a single component?

I am currently using Next.js Here is the structure I have: https://i.stack.imgur.com/jRQBS.png I am in need of opening the same component for multiple URLs, such as 'http://localhost:3000/hakkimizda', 'http://localhost:3000/cerez-politika ...

Encountering the "React Hook useEffect missing dependency" warning for a state variable that does not actually need to be included in the dependency array

My eslint is throwing an error for react-hooks/exhaustive-deps. I believe my code is correct as the function should only execute when there is a change in the pathname: const pathname = usePathname(); useEffect(() => { setNavigation( navig ...

Opening a window in ExtJS when another window is already open

It seems like I'm having trouble opening a new window on top of another window that is already open in ExtJS 6. I have tried setting the model to true and bringToFront to true, but unfortunately, neither of them is working as expected. https://i.sstat ...

Looking to retrieve the specific clientX and clientY JavaScript Position within a child div element on a Wordpress Page?

I've implemented a highlight hover map in JavaScript that displays an 'info box' div when hovering over a specific area at . However, I'm encountering an issue where the 'info box' doesn't appear precisely at the mouse lo ...

To complete Mocha tests, ensure to use the done() method. However, keep in mind that the resolution method is too specific. Choose either to specify a callback *or* return a Promise, but not both simultaneously

Encountering a frustrating issue with a mocha test. When I leave it alone, it freezes and displays: Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. If I include `Pro ...

Conceal list items by clicking elsewhere on the page

Currently, I am facing an issue with my search user functionality. Whenever a user clicks anywhere else on the page, the list of results does not disappear unless the user manually deletes all the words they have typed. This behavior is not ideal and despi ...

How to Delete Multiple Rows from an Angular 4 Table

I have successfully figured out how to remove a single row from a table using splice method. Now, I am looking to extend this functionality to remove multiple rows at once. html <tr *ngFor="let member of members; let i = index;"> <td> ...

pressing the enter key to submit form

Searching for videos is presenting a challenge for me when I try to submit the search form by pressing enter, but everything works fine when I click the button. After clicking, the text gets cleared and the /search page loads with the search index displa ...

Unable to move cursor in contenteditable section

I am currently working on developing a rich text editor in React, but I have encountered an issue that has me stuck. The problem I am facing is that as I type each character, the insertion point does not update accordingly, causing the cursor to remain stu ...

Headers cannot be sent to the client after they have already been set in Axios within Next.js

For additional discussion on this issue, please refer to the GitHub thread at - https://github.com/axios/axios/issues/2743 In my Next.js project, I am using Axios and occasionally encounter an error related to interceptors when returning a Promise.reject. ...