[英]How to add Account name to a contact in Dynamics 365
我正在将Alexa-php-toolkit用于Dynamics 365 https://github.com/AlexaCRM/php-crm-toolkit ,使用此工具我可以成功创建新联系人,但是当我无法向该联系人添加帐户名时试试我得到这个错误:
注意:无法在第263行的../vendor/alexacrm/php-crm-toolkit/src/Entity.php中设置联系人实体的属性accountid。
这是我的剧本。
<?php
//URL: https://github.com/AlexaCRM/php-crm-toolkit
/**
* Use init.php if you didn't install the package via Composer
*/
use AlexaCRM\CRMToolkit\Client as OrganizationService;
use AlexaCRM\CRMToolkit\Settings;
require_once '../vendor/autoload.php';
require_once '../vendor/alexacrm/php-crm-toolkit/init.php';
require_once 'config.php';
require_once 'includes/db.php';
$db = new DB();
$options = getAuth();
$serviceSettings = new Settings( $options );
$service = new OrganizationService( $serviceSettings );
$accountId = 'a2536507-018d-e711-8115-c4346bac0a5f';
// create a new contact
$contact = $service->entity( 'contact' );
$contact->accountid = $accountId;
$contact->firstname = 'Test';
$contact->lastname = 'Contact12';
$contact->jobtitle = 'Business Analyst';
$contact->mobilephone = '1002345679';
$contact->fax = '9902345679';
$contact->emailaddress1 = 'john.doe1@example.com';
$contact->address1_line1 = '119 Cambridge';
$contact->address1_line2 = 'Apt 22';
$contact->address1_city = 'Houston';
$contact->address1_stateorprovince = 'TX';
$contact->address1_postalcode = '77009';
$contact->address1_country = 'US';
$contactId = $contact->create();
echo $contactId;
?>
问题中有这行代码:
$contact->accountid = $accountId;
首先,联系人的上级帐户被保存在parentcustomerid
字段中,该字段是一个特殊的查找字段,可以存储指向帐户或联系人实体的链接 。 字段accountid
和parentcontactid
有助于在后台处理此问题,但通常不可用。 您需要使用parentcustomerid
字段。
其次,使用查找(外键)时的另一个问题是您需要传递实体类型(表名)。
正确的代码可能如下所示:
$accountRef = $client->entity( 'account' );
$accountRef->ID = $accountId;
$contact->parentcustomerid = $accountRef;
要么
$contact->parentcustomerid = new EntityReference( 'account', $accountId );
这些示例来自问题清单 ,已调整,但未经测试。 我希望它是可行的示例,而不是功能要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.