我正在尝试编写一个在创建帐户时会触发的插件。如果有原始潜在客户,我想在潜在客户中获取公司名称并将其放入帐户名称字段中。我不确定该怎么做才能从主要实体中获取信息。
我有以下代码(我会不断更新)...
Entity member = service.Retrieve("lead",
((EntityReference)account["originatingleadid"]).Id, new ColumnSet(true));
if (member.Attributes.Contains("companyname"))
{
companyName = member.Attributes["companyname"].ToString();
}
if (context.PostEntityImages.Contains("AccountPostImage") &&
context.PostEntityImages["AccountPostImage"] is Entity)
{
accountPostImage = (Entity)context.PostEntityImages["AccountPostImage"];
companyName = "This is a test";
if (companyName != String.Empty)
{
accountPostImage.Attributes["name"] = companyName;
service.Update(account);
}
}
答案 0 :(得分:1)
铅是否与帐户相关联?只需使用IOrganizationService.Retrieve方法即可 要检索正确的潜在客户(假设您拥有来自帐户实体的潜在客户ID)..
在插件的execute方法中创建organizationService。
http://msdn.microsoft.com/en-us/library/gg334504.aspx
这里有一个很好的例子来编写插件:
http://mscrmkb.blogspot.co.il/2010/11/develop-your-first-plugin-in-crm-2011.html?m=1
答案 1 :(得分:1)
我现在不打算破坏你的乐趣,但一般的想法是:
哪些步骤可以解决您的问题? :)
与往常一样,我建议在fetchXML之前使用查询表达式。 YMMV