我是Dynamics CRM 2013 SDK的新手,并将其与powershell一起使用,我设法创建了新的联系人,将其关联到帐户,更新等等,
但是,我无法找到如何将联系人与合同/产品关联/链接,或者以相反的方式将联系人添加为合同/产品成员,
这里是我的代码:
## 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)
现在,将它与产品/合同相关联的步骤是什么? [如果可能,[Powershell代码更可取]
由于
答案 0 :(得分:0)
这应该是您在c#中所需要的。如果您要使用自定义关系,则只需将关系模式名称设置为该Relationship对象即可。
// 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);