1
我想與同事共享gsheet,他們應該能夠運行腳本將聯繫人從工作表複製到自己的聯繫人。 我想創建一個MyCorp1 ContactGroup並添加聯繫人。我想檢查用戶是否已經創建了這個組。找不到檢查這個的方法。有沒有解決方法?不幸的是,如果我嘗試創建兩次或更多組,它會創建重複項。如何檢查ContactGroup是否存在
在此先感謝 的Gabor
function addCont(row){
var contact = ContactsApp.createContact(row[1], row[0], row[5]);
//if not empty
if (row[3] != "") {contact.setMobilePhone(row[3]);}
if (row[4] != "") {contact.setWorkPhone(row[4]);}
var myGroup = ContactsApp.getContactGroup('MyCorp1');
myGroup.addContact(contact);
}
//-----------------------------------------------------------------------------------
function delcreateGRP(){
var myGroup = ContactsApp.getContactGroup('MyCorp1');
myGroup.deleteGroup();
ContactsApp.createContactGroup('MyCorp1');
}
//-----------------------------------------------------------------------------------
function copyContacts() {
var startRow = 1; // First row of data to process
// This is the Request Spreadsheet
var ss = SpreadsheetApp.openById(REQUEST_SPREADSHEET_ID);
var sheet = ss.getSheets()[0];
// Fetch all the data from the Request Spreadsheet
// getRowsData was reused from Reading Spreadsheet Data using JavaScript Objects
//var data = getRowsData(sheet);
//var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
Logger.log('datalength: ' + data.length);
for (var i = startRow; i < data.length; ++i) {
var row = data[i];
row.rowNumber = i + 2;
addCont(row);
}
}