我刚刚得到一个asp.net webforms应用程序的要求,它必须与MS Dynamics 365 CRM集成。我从来没有做过Dynamics 365的开发,但无论如何,我已经设法使用.net sdk与CRM连接,并创建了一个铅和销售文献实体。我的意图是通过去实现我们可以做什么 Dynamics 365 portal --> Lead --> related --> Activities--> Sales Literature
:
所以,我想用.net sdk建立这两个实体(线索和销售文献)之间的关系,这是我的代码。
AssociateRequest association = new AssociateRequest
{
Target = new EntityReference(leadEntity.LogicalName, leadid),
RelatedEntities = new EntityReferenceCollection
{
new EntityReference(SLEntity.LogicalName, SLID)
},
Relationship = new Relationship("Lead_SalesLiterature"),
RequestId = new Guid()
};
// Execute the request.
CRMService.Execute(association);
但是这段代码无法建立关系,因为 CRMService.Execute(association);
说:"System.ServiceModel.FaultException`1: 'The Entity Relationship with SchemaName = 'SalesLiterature_Lead' not found in MetadataCache'。
System.ServiceModel.FaultException`1: "The Entity Relationship with SchemaName = 'SalesLiterature_Lead' was not found in the MetadataCache'
我已经检查了两个 牵头实体参考 和 销售文献实体参考 但找不到这个关系的Schema名称。是我错过了什么,还是这是不可能的?
我坚信你截图中显示的 "销售资料 "是一个自定义的活动实体,它与OOB "销售资料 "实体不同。
要创建一个以Lead为对象的自定义实体(活动),请使用以下方法 regardingobjectid
可以用这段代码来完成。只要把 task
用您的实体名称
Entity followup = new Entity("task");
followup["subject"] = "Sample task - an activity";
followup["description"] = "Sample description";
followup["scheduledstart"] = DateTime.Now;
followup["scheduledend"] = DateTime.Now.AddDays(2);
Guid regardingobjectid = new Guid("26ADDD07-D9F4-E711-8138-E0071B715B11"); //leadid
string regardingobjectidType = "lead";
followup["regardingobjectid"] = new EntityReference(regadingobjectidType,regardingobjectid);
// Create the followup activity
CRMService.Create(followup);