2012-05-28 2 views
0

고객이 작성하는 Google 양식이 있습니다. 설문 조사에 응답 할 때마다 양식을 Google 연락처에 자동으로 추가하려면 어떻게해야합니까? 난 그냥 몇 가지 테스트 데이터를 실행하려고 할 때이 스크립트를 사용하려고하지만 오류를 받고 있어요은 내 Google 양식에서 자동으로 Google 연락처를 만듭니다.

내 Gmail에서 새 연락처를 만들 때마다 붙여 복사하고 싶지 해달라고

function onFormSubmit(e) { 
    var timestamp = e.values[0]; 
    var firstName= e.values[1]; 
    var lastName= e.values[2]; 
    var email= e.values[3]; 
    var phone= e.values[4]; 
    ContactsApp.createContact(timestamp , firstName , lastName , email , phone); 
} 

TypeError: Cannot read property "values" from undefined. (line 2

+0

스크립트 편집기를 통해이 기능을 수동으로 실행하면 자동으로 실행될 때와 같이 'e'매개 변수 개체가 표시되지 않습니다. 그것이 '정의되지 않은'이유입니다. 수동으로 실행하려면'e' 매개 변수를 테스트 값으로 초기화해야합니다. –

답변

0

함수에 전달되는 이벤트가 없으므로 수동으로 함수를 실행하려고하면 오류 메시지가 표시됩니다.

나머지 게시물을 무시하십시오 (Henrique의 의견 참조).

According to the documentation:

An event is passed to every event handler as the argument (e) . You can add attributes to the (e) argument that further define how the trigger works or that capture information about how the script was triggered.

If you use the attributes, you must still set the trigger from the Resources menu, as described in the sections above.

https://developers.google.com/apps-script/guide_events#TriggerAttributes

I can't explain why this is the case, but it seems you need to use the simple event handler (ie naming the function onFormSubmit), as well as applying an installable event handler to that same function. Then, for me at least, it works as expected.

HTH, Adam

+0

폼 제출시 실행되도록 트리거를 설정했습니다. 즉시 내 Google 계정에 새 연락처가 표시되어야합니까? 아직 나를 위해 일하지 않았다 – user1420867

+0

function onFormSubmit (e) { var firstName = e.values ​​[1]; var lastName = e.values ​​[2]; var email = e.values ​​[3]; var phone = e.values ​​[4]; var contact = ContactsApp.createContact (firstName, lastName, email, phone); } – user1420867

+1

@AdamL'onitpen'과'onEdit'처럼 'form sumit'을위한 간단한 이벤트 핸들러가 없습니다. 따라서 onFormSubmit이라는 이름은 아무런 영향을 미치지 않으며 모든 이름이 될 수 있습니다. 중요한 것은 설치 가능한 트리거를 설정하는 것입니다. –

0

createContact 함수에는 "phone"인수가 없습니다. 디버깅하기가 더 어렵 기 때문에 트리거를 생성하기 전에 간단하게 간단한 함수를 작성하여 올바르게 작성했는지 확인해 보았습니까?

또한 양식 제출 매개 변수가있는 old error이 기억납니다. 어쨌든, 모든 매개 변수에 toString을 추가해도 문제가되지 않습니다. 예 :

var email = e.values[3].toString(); //just to be sure 
+0

function onFormSubmit (e) { var timestamp = e.values ​​[0]; var firstName = e.values ​​[1]; var lastName = e.values ​​[2]; var email = e.values ​​[3] .toString(); // 확실하게 ContactsApp을 확인하십시오.createContact (이름, 성, 이메일); } ok는 매우 간단한 3 열 시트를 사용하여 이와 같이 시도했지만 아직 생성 된 연락처는 없습니다. 내 방아쇠가 스프레드 시트/양식에서 제출하도록 설정되었습니다. – user1420867

+0

간단하고 직접적인 코드를 사용하여 연락처를 추가하고 나중에 "복잡성"을 추가하는 것이 좋습니다 (예 : 트리거에서 실행). 너 해봤 어? –

+0

그 방법을 모르는 경우 제안 사항에 트리거가 없으므로 트리거를 삭제 하시겠습니까? 그 간단한 코드는 어떻게 생겼을까요? 같은 스크립트 영역에 있습니까? – user1420867