Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8759493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:49:17+00:00 2026-06-13T14:49:17+00:00

Here is the function that creates the array: //retrieve calendar id’s function getCalendarId(){ gapi.client.load(‘calendar’,

  • 0

Here is the function that creates the array:

//retrieve calendar id's
function getCalendarId(){
    gapi.client.load('calendar', 'v3', function() {
        var request = gapi.client.calendar.calendarList.list();
        request.execute(function(resp) {
            var calendarID = [];
            for (var i = 0; i < resp.items.length; i++) {
                var ID = resp.items[i].id;
                var calendarSummary = resp.items[i].summary;
                var calendarLocation = resp.items[i].location;
                var calendarDescription = resp.items[i].description;
                if (calendarDescription && calendarDescription.indexOf("Resource Tracker") != -1) {
                        var index = calendarID.length;
                        calendarID[index] = ID;
                }//endif
            }//end for
            console.log(typeof calendarID);
            return calendarID;
        });//end request.execute function(resp)
    });//end client.load function
}//end getCalendarId

And here is the function that assigns it:

function submitEvents(numHorses){
   var startdate = $("#from").val();
   var enddate = $("#to").val();
   var horsetypes = [];
   var calid = [];
   console.log(typeof(calid));
   calid = getCalendarId();
   console.log(typeof(calid));
   for (i=0; i<numHorses;i++){
      horsetypes[i] = $( "#type"+i).val();
      addEvent(calid[i%calid.length], startdate, enddate, horsetypes[i]);
   }//end for           
  };//end submitEvents

When I check the type, calendarID is an object just before being returned, and calid is an object when I declare it, but when I make the assignment calid=getCalendarID(); the type of calid becomes undefined.

I’ve been banging my head against the wall for a while now; any help is appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:49:18+00:00Added an answer on June 13, 2026 at 2:49 pm

    Nothing returns from the outermost function; it has no return value, so the variable set to the return value of the function is set to undefined. The inner anonymous function contains the return, which may or may not have meaning to the API (probably not).

    The real problem is that the call to the calendar API might take an arbitrary amount of time (it’s asynchronous), so you can’t set the value within a single (synchronous) function and expect it to work. Javascript will not stop executing while your request makes its way to and from remote servers, and you really don’t want it to.

    Similar problem/answer: javascript function return not working

    Since you may be using getCalendarId other places, you could consider having it take a function of its own, and call that when the Google Calendar function returns:

    function getCalendarId(callback){                            // !!!
      gapi.client.load('calendar', 'v3', function() {
        var request = gapi.client.calendar.calendarList.list();
        request.execute(function(resp) {
          var calendarID = [];
          for (var i = 0; i < resp.items.length; i++) {
            // omitted for brevity
          }//end for
          console.log(typeof calendarID);
          callback(calendarID);                                  // !!!
        });//end request.execute function(resp)
      });//end client.load function
    }//end getCalendarId
    
    function submitEvents(numHorses){
      // omitted for brevity
      getCalendarId(function(calid) {                            // !!!
        console.log(typeof(calid));
        for (i=0; i<numHorses;i++){
          // omitted for brevity
        }//end for
      });
    };//end submitEvents
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the function that i am using: $('.urlz').click(function (event) { event.preventDefault(); var url
I have created a function that creates a dynamic string array with dynamic string
I have an function that creates an array of words from a string, counts
I've got a function here that is meant to look through a list of
Here is a simple function that converts a string to an integer. int str2int(char
Here is an (artificial) example of using a function that returns an anonymous struct
Here's a brief rundown of my issue: I have a JavaScript function that gets
Here is what I'm trying to do: - i need a function that when
I have a function that uses the Google Blobstore API, and here's a degenerate
Here's the story... I have a jQuery function that does something, this function is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.