将联系人关联到 Products/Contracts - Dynamics CRM

Associate Contacts to Products/Contracts - Dynamics CRM

我是 Dynamics CRM 2013 SDK 的新手,将它与 powershell 一起使用,我设法创建了新的联系人,将其关联到帐户,更新等等,

但是我找不到如何将联系人 associate/link 添加到 contracts/products,或者以相反的方式将联系人添加为 contract/product 成员,

例如我的代码:

## Create a contact

$Contact = New-Object -TypeName Microsoft.Xrm.Sdk.Entity -ArgumentList "contact"
$Contact["fullname"] = "demo-contact"
$Contact["emailaddress1"] = "contact@demo.com"

$id = $service.Create($Contact);

## Associate Contact to Account(Customer)

$accountToUpdate = New-Object -TypeName Microsoft.Xrm.Sdk.Entity -ArgumentList "contact"
$accountToUpdate.Id = $id;
$Customer = $Account.ToEntityReference()
$accountToUpdate["parentcustomerid"] = $Customer
$service.Update($accountToUpdate)

现在,将其关联到 product/contract 的步骤是什么? [如果可能,最好使用 Powershell 代码]

谢谢

这应该是您在 c# 中所需要的。如果您有要使用的自定义关系,则只需将关系模式名称设置到该关系对象中即可。

// Create an object that defines the relationship between the contact and contract.
Relationship relationship = new Relationship("contract_customer_contacts");

//Set up the EntityReferenceCollection that you are associating the contact to
EntityReferenceCollection contractRefs = new EntityReferenceCollection().Add(
    new EntityReference(Contract.EntityLogicalName, _contractId));

//Associate the contact with the contract(s).
_service.Associate(Contact.EntityLogicalName, _contactId, relationship,
contractRefs);