[英]Google Apps Script phone numbers from AD
I'm trying to create a script in Google Apps Script that gets users' phone numbers from AD and copies them into Google Sheets.我正在尝试在 Google Apps 脚本中创建一个脚本,从 AD 获取用户的电话号码并将它们复制到 Google 表格中。
try {
if(user.phones[0].type = 'home'){
prop.push(user.phones[0].value);
}
if (user.phones[1].type = 'mobile'){
prop.push(user.phones[1].value );
}
if(user.phones[2].type = 'work'){
prop.push(user.phones[2].value);
}
else{
prop.push('');
}
}
catch(err){
prop.push('');
}
Now that does work, but it puts numbers in unwanted cell order.现在确实有效,但它会将数字置于不需要的单元格顺序中。 It seems to type: 'work' 'home' 'mobile'.
它似乎在输入:“工作”“家庭”“移动”。 Also, if the user does not have 3 of those numbers, so fe Only 'mobile', this script puts it first where 'work' should be.
此外,如果用户没有这些号码中的 3 个,那么 fe Only 'mobile',此脚本将其放在第一个应该是 'work' 的位置。 I was hoping this code would put them in a specific cell order: 'home', 'mobile', 'work'.
我希望这段代码会将它们置于特定的单元格顺序中:“家庭”、“移动”、“工作”。 Any ideas?
有任何想法吗?
=
use ===
=
使用===
if
hasn't and else
.if
和else
。 If you don't want misplaced data, then you should add else{ prop.push(''); }
else{ prop.push(''); }
else{ prop.push(''); }
after each of them.else{ prop.push(''); }
之后。 The following example uses Array.prototype.forEach
and switch
instead of several if
下面的例子使用
Array.prototype.forEach
和switch
而不是几个if
const prop = new Array(4).fill('');
user.phones.forEach(phone => {
switch(phone.type){
case 'home':
prop[0] = phone.value;
break;
case 'work':
prop[1] = phone.value;
break;
case 'mobile':
prop[2] = phone.value;
break;
default: // This will manage other phone types
prop[3] = prop[3].length === 0 ? phone.value : [prop[3], phone.value].join(',');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.