Add a Calendar event help

Viewing 1 reply thread
  • Author
    Posts
  • November 26, 2021 at 7:10 AM #45801

    Hello,
    I would like to add/update an event with hour (not all day) from two fields, one for the date, one for the hour.
    I’m new in scripting and I can’t find an example with hour included.
    Thanks for your help !

    November 26, 2021 at 11:21 PM #45807

    Brendan
    Keymaster

    Hi Jean-Christophe,

    You would just set the all_day parameter to false and set the Date to have a specific time.

    https://www.w3schools.com/jsref/jsref_sethours.asp

    function Add_And_Update_Event() {
    
    	var event_info = {"calendar_name" : "Work",
    			"title" : "Test Event 1",
    			"location" : "Big Ben, London, UK",
    			"notes" : "This is a note",
    			"url" : "https://www.tapforms.com",
    			"all_day" : false};
    
    	var start_date = new Date();
    
            // Set the time to 15:30:00
            start_date.setHours(15, 30, 0);
    
    	// Create end Date instance 1 hour later
    	var end_date = new Date();
            end_date.setHours(16, 30, 0);
    
    	var identifier = Utils.addToCalendar(event_info, start_date, end_date);
    	console.log(identifier);
    	event_info["title"] = "Hello Event 2";
    	Utils.updateCalendarEvent(identifier, event_info, start_date, end_date);
    
    }
    
    Add_And_Update_Event();

    You can copy this code into a new Form Script to test it out.

Viewing 1 reply thread

You must be logged in to reply to this topic.