这是我的第一个问题,我感到紧张。
在这里,我想通过谷歌联系人获取客户全名和地址。但它不起作用。寻找专家帮助
function importContact() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Stock" ) {
var r = s.getActiveCell();
var phone = r.getValue()
if( r.getColumn() == 10 ) {
var nextCell1 = r.offset(0, 1);
var nextCell2 = r.offset(0, 2);
var contacts = ContactsApp.getContactsByPhone(phone,'Other');
for(var i = 0, iLen = contacts.length; i < iLen; i++) {
var fullname = contacts[i].getFullName();
var address = contacts[i].getAddresses(ContactsApp.Field.HOME_ADDRESS);
if(fullname) {
nextCell1.setValue(fullname);
nextCell2.setValue(address);
} else {
nextCell1.setValue('New Customer');
}
}
}
}
}
非常感谢
答案 0 :(得分:1)
这似乎对我有用。但我没有任何联系人的地址,所以我无法验证。
<!DOCTYPE html>
<?php
if( isset( $_REQUEST['update'] ))
{
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "bc140401259_DB";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$employeeID="";
if ( ! empty($_POST['empID'])){
$employeeID = $_POST['empID'];
}
$Name="";
if ( ! empty($_POST['name'])){
$Name = $_POST['name'];
}
$Address="";
if ( ! empty($_POST['address'])){
$Address = $_POST['address'];
}
$Dateofbirth="";
if ( ! empty($_POST['DOB'])){
$Dateofbirth = $_POST['DOB'];
}
$Salary="";
if ( ! empty($_POST['salary'])){
$Salary = $_POST['salary'];
}
$timestamp="";
if ( ! empty($_POST['timeIn'])){
$timestamp = $_POST['timeIn'];
}
$sql = "UPDATE Employee SET Name = $Name, Address = $Address, Dateofbirth = $Dateofbirth, Salary = $Salary, Timein = $timestamp where empID = $employeeID";
if (mysqli_query($conn, $sql)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
mysqli_close($conn);
}
?>
<html>
<body>
<form action="" method="post">
<h2>Add Employee Form</h2>
Employee ID: <input type="text" name="empID" >
<br><br>
Name: <input type="text" name="name" >
<br><br>
Address: <input type="text" name="address" >
<br><br>
Date of Birth: <input type="text" name="DOB" >
<br><br>
Salary: <input type="text" name="salary" >
<br><br>
Time In: <input type="text" name="timeIn" >
<br><br>
<input type="submit" name="update" value="UPDATE" />
</form>
</body>
</html>
答案 1 :(得分:0)
解决方案#1似乎没有完全发挥作用,因此经过调试和修改,直到:
试图评论库珀的一个,但没有足够的声誉。希望这没关系,如果需要,我准备删除我的回复。
关于代码的一些注释:
var address = addresses[0].getAddress()
显然是第一个解决方案中的主要缺失链接; if( s.getName() == "Stock" )
中的“Stock”。现在应该很明显:我是学习者,不是专家。任何改进的建议都非常受欢迎。
function importContact()
{
var ss=SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getActiveSheet();
if( s.getName() == "Stock" )
{
var r = s.getActiveCell();
var phone = r.getValue();
if( r.getColumn() == 1 )
{
var nextCell1 = r.offset(0, 1);
var nextCell2 = r.offset(0, 2);
var contacts = ContactsApp.getContactsByPhone(phone);
if(contacts.length == 0)
{
nextCell1.setValue('New Customer');
}
else
{
for(var i = 0; i < contacts.length; i++)
{
var fullname = contacts[i].getFullName();
nextCell1.setValue(fullname);
var addresses = contacts[i].getAddresses(ContactsApp.Field.HOME_ADDRESS);
if (addresses.length == 0)
{
nextCell2.setValue("Not Available");
}
else
{
var address = addresses[0].getAddress() //this was the missing link in the first solution, apparently
nextCell2.setValue(address);
}
}
}
}
}
}