Class CompanyField
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
已弃用的方法
deleteCompanyField()
已弃用。此函数已废弃,不应在新脚本中使用。
删除此“公司”字段。
// Deletes the first company associated with contact 'John Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const company = contacts[0].getCompanies()[0];
company.deleteCompanyField();
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
getCompanyName()
已弃用。此函数已废弃,不应在新脚本中使用。
获取公司名称。
// Logs company name for all companies associated with contact 'John Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const companies = contacts[0].getCompanies();
for (const i in companies) {
Logger.log(companies[i].getCompanyName());
}
返回
String
- 公司名称
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
getJobTitle()
已弃用。此函数已废弃,不应在新脚本中使用。
获取职位。
// Logs job title for all companies associated with contact 'John Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const companies = contacts[0].getCompanies();
for (const i in companies) {
Logger.log(companies[i].getJobTitle());
}
返回
String
- 职位
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
isPrimary()
已弃用。此函数已废弃,不应在新脚本中使用。
获取这是否为主公司。
// Logs true or false depending on whether each company is the primary
// company for contact 'John Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const companies = contacts[0].getCompanies();
for (const i in companies) {
Logger.log(companies[i].isPrimary());
}
返回
Boolean
- 是否为主
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
setAsPrimary()
已弃用。此函数已废弃,不应在新脚本中使用。
将此公司设为主公司,并取消设定之前的主公司。
// Sets the first company associated with contact 'John Doe' as primary
const contacts = ContactsApp.getContactsByName('John Doe');
const company = contacts[0].getCompanies()[0];
company.setAsPrimary();
返回
CompanyField
- 此公司字段,适用于串联
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
setCompanyName(company)
已弃用。此函数已废弃,不应在新脚本中使用。
设置公司名称。
// Sets the company name for the first company associated with contact 'John
// Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const company = contacts[0].getCompanies()[0];
company.setCompanyName('ACME Corp');
参数
名称 | 类型 | 说明 |
company | String | 公司的新名称 |
返回
CompanyField
- 此公司字段,适用于串联
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
setJobTitle(title)
已弃用。此函数已废弃,不应在新脚本中使用。
设置职位。
// Sets the job title for the first company associated with contact 'John Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const company = contacts[0].getCompanies()[0];
company.setJobTitle('Manager');
参数
名称 | 类型 | 说明 |
title | String | 此公司联系人的新职位 |
返回
CompanyField
- 此公司字段,适用于串联
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eThe \u003ccode\u003eCompanyField\u003c/code\u003e object, representing a company field in a contact, is deprecated and should not be used in new scripts.\u003c/p\u003e\n"],["\u003cp\u003eInstead of using \u003ccode\u003eCompanyField\u003c/code\u003e, use the People API advanced service for managing contact information.\u003c/p\u003e\n"],["\u003cp\u003eAll methods associated with \u003ccode\u003eCompanyField\u003c/code\u003e, such as \u003ccode\u003edeleteCompanyField()\u003c/code\u003e, \u003ccode\u003egetCompanyName()\u003c/code\u003e, \u003ccode\u003egetJobTitle()\u003c/code\u003e, \u003ccode\u003eisPrimary()\u003c/code\u003e, \u003ccode\u003esetAsPrimary()\u003c/code\u003e, \u003ccode\u003esetCompanyName()\u003c/code\u003e, and \u003ccode\u003esetJobTitle()\u003c/code\u003e, are deprecated.\u003c/p\u003e\n"],["\u003cp\u003eScripts using these deprecated methods required authorization with the \u003ccode\u003ehttps://www.google.com/m8/feeds\u003c/code\u003e scope.\u003c/p\u003e\n"]]],["The `CompanyField` in Contacts is deprecated; the People API should be used instead. It allowed managing company details for contacts, including deleting the company field, getting the company name and job title, and determining if a company was set as primary. You could also set a company as primary, modify the company name, and change the job title associated with a specific company. All these functions are deprecated, requiring authorization with the `https://www.google.com/m8/feeds` scope.\n"],null,["# Class CompanyField\n\nCompanyField\n\n\n**Deprecated.** Instead, use the [People API advanced\nservice](/apps-script/advanced/people)\n\nCompany field in a Contact. \n\n### Deprecated methods\n\n| Method | Return type | Brief description |\n|----------------------------------------------------|-------------------|-----------------------------------------------------------------------------------------------|\n| [deleteCompanyField()](#deleteCompanyField()) | `void` | Deletes this company field. |\n| [getCompanyName()](#getCompanyName()) | `String` | Gets the company name. |\n| [getJobTitle()](#getJobTitle()) | `String` | Gets the job title. |\n| [isPrimary()](#isPrimary()) | `Boolean` | Gets whether this is the primary company. |\n| [setAsPrimary()](#setAsPrimary()) | [CompanyField](#) | Sets this company as the primary company, and unsets whatever company was previously primary. |\n| [setCompanyName(company)](#setCompanyName(String)) | [CompanyField](#) | Sets the company name. |\n| [setJobTitle(title)](#setJobTitle(String)) | [CompanyField](#) | Sets the job title. |\n\nDeprecated methods\n------------------\n\n### `delete``Company``Field()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nDeletes this company field.\n\n```javascript\n// Deletes the first company associated with contact 'John Doe'\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst company = contacts[0].getCompanies()[0];\ncompany.deleteCompanyField();\n```\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n### `get``Company``Name()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nGets the company name.\n\n```javascript\n// Logs company name for all companies associated with contact 'John Doe'\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst companies = contacts[0].getCompanies();\nfor (const i in companies) {\n Logger.log(companies[i].getCompanyName());\n}\n```\n\n#### Return\n\n\n`String` --- the name of the company\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n### `get``Job``Title()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nGets the job title.\n\n```javascript\n// Logs job title for all companies associated with contact 'John Doe'\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst companies = contacts[0].getCompanies();\nfor (const i in companies) {\n Logger.log(companies[i].getJobTitle());\n}\n```\n\n#### Return\n\n\n`String` --- the job title\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n### `is``Primary()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nGets whether this is the primary company.\n\n```javascript\n// Logs true or false depending on whether each company is the primary\n// company for contact 'John Doe'\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst companies = contacts[0].getCompanies();\nfor (const i in companies) {\n Logger.log(companies[i].isPrimary());\n}\n```\n\n#### Return\n\n\n`Boolean` --- whether this is primary\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n### `set``As``Primary()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nSets this company as the primary company, and unsets whatever company was previously primary.\n\n```javascript\n// Sets the first company associated with contact 'John Doe' as primary\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst company = contacts[0].getCompanies()[0];\ncompany.setAsPrimary();\n```\n\n#### Return\n\n\n[CompanyField](#) --- this company field, useful for chaining\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n### `set``Company``Name(company)`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nSets the company name.\n\n```javascript\n// Sets the company name for the first company associated with contact 'John\n// Doe'\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst company = contacts[0].getCompanies()[0];\ncompany.setCompanyName('ACME Corp');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------|----------|------------------------------|\n| `company` | `String` | the new name for the company |\n\n#### Return\n\n\n[CompanyField](#) --- this company field, useful for chaining\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n### `set``Job``Title(title)`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nSets the job title.\n\n```javascript\n// Sets the job title for the first company associated with contact 'John Doe'\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst company = contacts[0].getCompanies()[0];\ncompany.setJobTitle('Manager');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|----------|---------------------------------------------------|\n| `title` | `String` | the new job title for the contact at this company |\n\n#### Return\n\n\n[CompanyField](#) --- this company field, useful for chaining\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`"]]