我是你在CRM插件開發中稱之爲「n00b」的東西。我正在嘗試爲Microsoft Dynamics CRM 2011編寫一個插件,當您創建新聯繫人時,該插件將創建一個新的活動實體。我希望這個活動實體與聯繫實體相關聯。CRM2011 - 「給定的密鑰不在字典中」
這是我當前的代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
namespace ITPH_CRM_Deactivate_Account_SSP_Disable
{
public class SSPDisable_Plugin: IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
if (context.InputParameters.Contains("Target") && context.InputParameters["target"] is Entity)
{
Entity entity = context.InputParameters["Target"] as Entity;
if (entity.LogicalName != "account")
{
return;
}
Entity followup = new Entity();
followup.LogicalName = "activitypointer";
followup.Attributes = new AttributeCollection();
followup.Attributes.Add("subject", "Created via Plugin.");
followup.Attributes.Add("description", "This is generated by the magic of C# ...");
followup.Attributes.Add("scheduledstart", DateTime.Now.AddDays(3));
followup.Attributes.Add("actualend", DateTime.Now.AddDays(5));
if (context.OutputParameters.Contains("id"))
{
Guid regardingobjectid = new Guid(context.OutputParameters["id"].ToString());
string regardingobjectidType = "account";
followup["regardingobjectid"] = new EntityReference(regardingobjectidType, regardingobjectid);
}
service.Create(followup);
}
}
}
但是,當我嘗試運行這段代碼:我得到一個錯誤,當我嘗試創建在CRM環境中一個新的聯繫人。錯誤是:「給定的密鑰不在字典中」(鏈接* 1)。當我嘗試保存新聯繫人時,該錯誤彈出正確。
鏈接* 1:http://puu.sh/4SXrW.png
(翻譯粗體文字: 「業務流程錯誤」)
我認爲錯誤是'activitypointer',你需要指定確切活動實體類型你想創建(任務,約會,...) –
任何建議,我怎麼做?我是一名CRM插件開發的初學者。我能得到的所有幫助都非常感謝。 –
您的意思是您希望在用戶創建聯繫人時創建活動,但在代碼中您正在查找「帳戶」實體。 – Scorpion