1

GoogleフォームとGoogleカレンダーを使用してチームオンコールスケジューラを作成しようとしています。各チームには、プライマリとセカンダリの両方をオンコールにするオプションがあります。これまでは、Googleカレンダーにプライマリオプションを配置するコードを正常に取得できましたが、選択した場合、カレンダーにセカンダリを配置するコードを取得する方法を見つけることができません。私は他人からの答えを探して何かを見つけることができませんでした。あるいは、私がコーディングに新しいことを理解していないかもしれません。お手伝いできる人には、事前にありがとうございます。1つのGoogleフォームサブミッションから2つのGoogleカレンダーイベントを作成する

Jesse Spevack(http://www.jessespevack.com/blog/2016/2/9/turn-a-google-form-response-into-a-calendar-event)という名前で紳士にクレジットを与えてください。

function onFormSubmit() { 
    var eventObject = getFormResponse(); 
    var event = createCalendarEvent(eventObject); 
} 

function onFormSubmit() { 
    var eventObject, calendarTwoID; 

    eventObject = getFormResponse(); 

    calendarTwoID = 'Put the ID of the second calendar here'; 

    createCalendarEvent(eventObject);//Create first event 
    createCalendarEvent(eventObject, calendarTwoID);//Create second event 
} 

ここ

は私のコードは、これまで...

//Load the Moment.js library once. 
 
var moment = Moment.load(); 
 

 
var GLOBAL = { 
 
    //the id of the form we will use to create calendar events 
 
    formId : "xxxxx", 
 
    
 
    //the id of the calendar we will create events on 
 
    calendarId : "xxxx", 
 
    
 
    //a mapping of form item titles to sections of the calendar event 
 
    formMap : { 
 
    eventTitle: "Team Primary On-call", 
 
    startTime : "Primary start date/time", 
 
    endTime: "Primary end date/time", 
 
    description: "Primary On-call Contact", 
 
    }, 
 
} 
 

 
function onFormSubmit() { 
 
    var eventObject = getFormResponse(); 
 
    var event = createCalendarEvent(eventObject); 
 
} 
 

 
function getFormResponse() { 
 
    // Get a form object by opening the form using the 
 
    // form id stored in the GLOBAL variable object 
 
    var form = FormApp.openById(GLOBAL.formId), 
 
     //Get all responses from the form. 
 
     //This method returns an array of form responses 
 
     responses = form.getResponses(), 
 
     //find the length of the responses array 
 
     length = responses.length, 
 
     //find the index of the most recent form response 
 
     //since arrays are zero indexed, the last response 
 
     //is the total number of responses minus one 
 
     lastResponse = responses[length-1], 
 
     //get an array of responses to every question item 
 
     //within the form for which the respondent provided an answer 
 
     itemResponses = lastResponse.getItemResponses(), 
 
     //create an empty object to store data from the last 
 
     //form response 
 
     //that will be used to create a calendar event 
 
     eventObject = {}; 
 
    //Loop through each item response in the item response array 
 
    for (var i = 0, x = itemResponses.length; i<x; i++) { 
 
    //Get the title of the form item being iterated on 
 
    var thisItem = itemResponses[i].getItem().getTitle(), 
 
     //get the submitted response to the form item being 
 
     //iterated on 
 
     thisResponse = itemResponses[i].getResponse(); 
 
    //based on the form question title, map the response of the 
 
    //item being iterated on into our eventObject variable 
 
    //use the GLOBAL variable formMap sub object to match 
 
    //form question titles to property keys in the event object 
 
    switch (thisItem) { 
 
     case GLOBAL.formMap.eventTitle: 
 
     eventObject.title = thisResponse; 
 
     break; 
 
     case GLOBAL.formMap.startTime: 
 
     eventObject.startTime = thisResponse; 
 
     break; 
 
     case GLOBAL.formMap.endTime: 
 
     eventObject.endTime = thisResponse; 
 
     break; 
 
     case GLOBAL.formMap.description: 
 
     eventObject.description = thisResponse; 
 
     break; 
 
    } 
 
    } 
 
    return eventObject; 
 
} 
 

 
function createCalendarEvent(eventObject) { 
 
    //Get a calendar object by opening the calendar using the 
 
    //calendar id stored in the GLOBAL variable object 
 
    var calendar = CalendarApp.getCalendarById(GLOBAL.calendarId), 
 
     //The title for the event that will be created 
 
     title = eventObject.title, 
 
     //The start time and date of the event that will be created 
 
     startTime = moment(eventObject.startTime).toDate(), 
 
     //The end time and date of the event that will be created 
 
     endTime = moment(eventObject.endTime).toDate(); 
 
    //an options object containing the description and guest list 
 
    //for the event that will be created 
 
    var options = { 
 
    description : eventObject.description, 
 
    }; 
 
    try { 
 
    //create a calendar event with given title, start time, 
 
    //end time, and description and guests stored in an 
 
    //options argument 
 
    var event = calendar.createEvent(title, startTime, 
 
            endTime, options) 
 
    } catch (e) { 
 
     //delete the guest property from the options variable, 
 
     //as an invalid email address with cause this method to 
 
     //throw an error. 
 
     delete options.guests 
 
     //create the event without including the guest 
 
     var event = calendar.createEvent(title, startTime, 
 
             endTime, options) 
 
     } 
 
    return event; 
 
}

+0

アドオンを使用したくないかもしれませんが、それはあなたのために許容される溶液であれば、あなたは試みることができます.com/webstore/detail/data-director-for-forms/bjlicikmbfbjckkgemmiddonmigijpbj?authuser = 0) –

+0

入力いただきありがとうございます。残念ながら、Google Apps管理者によってブロックされているため、アドオンを使用することはできません。 –

答えて

0

変更するには、この機能でありますhttps://chrome.google([Chromeウェブストア]:へcreateCalendarEvent機能を変更します。

function createCalendarEvent(eventObject, calendarID) { 
    //Get a calendar object by opening the calendar using the 
    //calendar id stored in the GLOBAL variable object 
    var calendar; 

    if (calendarID) {//If ID is passed in 
    calendar = CalendarApp.getCalendarById(calendarID);//use the passed in ID 
    } else {//Otherwise use the global ID 
    calendar = CalendarApp.getCalendarById(GLOBAL.calendarId); 
    } 

    //The title for the event that will be created 
    var title = eventObject.title, 
    //The start time and date of the event that will be created 
    startTime = moment(eventObject.startTime).toDate(), 
    //The end time and date of the event that will be created 
    endTime = moment(eventObject.endTime).toDate(); 
+0

こんにちはサンディー、あなたのご意見ありがとうございました。これは、私は2つのカレンダーをプライマリ用に、もう1つをセカンダリ用に作成すると考えています。しかし、私は本当に使いやすさのためにそれを1カレンダーにすることを望んでいました。どのようにそれが行われるかもしれない任意のアイデア? –

関連する問題