我正在编写从db中提取的代码,并将信息填充为活动,我成功地将数据库中的字段添加到描述和主题字段,但我似乎无法获取它链接到一个帐户? 这是我试过的;将帐户链接到活动CRM
foreach (var phoneNumber in phoneNumbers)
{
var potentialMatches = _xrm.AccountSet.Where(account => account.Address1_Telephone2.Equals(phoneNumbers)).ToList();
if (potentialMatches.Count > 0)
{
var accountMatch = potentialMatches.First();
var actualCRMAccount = (Account) _xrm.Retrieve("Account", accountMatch.Id, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
if (actualCRMAccount != null)
{
//Is this correct way?
new ActivityParty()
{
PartyId = new EntityReference(Account.EntityLogicalName, actualCRMAccount.Id)
};
activityParties.Add(new ActivityParty() {Id = actualCRMAccount.Id});
}
}
}
//RegardingObjectId not working
//RegardingObjectId = new EntityReference(Account.EntityLogicalName, recordRow.Cells[0].Value.ToString);
newMsg.To = activityParties;
newMsg.Description = recordRow.Cells[0].Value.ToString();
newMsg.Subject = recordRow.Cells[2].Value.ToString();
_xrm.Create(newMsg);
编辑1: 当我运行它现在即时得到这个警告
类型的未处理的异常 'System.ServiceModel.FaultException`1' 发生在Microsoft.Xrm.Sdk.dll。
附加信息:在MetadataCache中找不到名称='Account'的实体。
这是它抛出警告
var actualCRMAccount = (Account)_xrm.Retrieve("Account", accountMatch.Id, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
为什么会变成这样的一段代码?
编辑2: 我用Account替换Account,见下文。
var actualCRMAccount = (Account)_xrm.Retrieve("account", accountMatch.Id, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
编辑3: 林现在试图做它的线索。但是当我添加这一点的代码。
newMsg.RegardingObjectId = activityParties;
我得到这个错误。
不能键入 'System.Collections.Generic.List' 隐式转换为 'Microsoft.Xrm.Client.CrmEntityReference'
如何能值赋给RegardingObjectId
。
感谢大家的帮助。
的:
.Equals(phoneNumber)
然后帐户记录的检索与此更换后的代码上面的代码不工作,行'newMsg.To = activityParties',不会将客户名称分配给活动? – AndroidAL
我看到你改变了发布的代码。位还是有问题: new ActivityParty() { PartyId = new EntityReference(Account。EntityLogicalName,actualCRMAccount.Id) }; activityParties.Add(new ActivityParty(){Id = actualCRMAccount.Id}); 应改为: activityParties.Add(新ActivityParty() { PartyId =新的EntityReference(Account.EntityLogicalName,actualCRMAccount.Id) }); 这应该工作。如果没有,那么检索到的帐户可能不存在。 –
嗨,最近有什么问题? – AndroidAL