![](/img/trans.png)
[英]CRM: Difference between creating Workflow and Workflow custom activity in C#
[英]Update created record in Custom Workflow Activity -CRM -C#
我创建了新实体。
我从该实体调用创建机会的自定义工作流活动实体。 它有效,但另外我必须根据创造的机会更改一些字段。 (我必须添加机会产品,并且必须为每个机会更改价目表)。
作为测试,我尝试在创建后更新帐户字段,但它失败了。 当我在创建之前填充此帐户字段时,它会起作用,因此与此无关。 这是代码的一部分:
Entity entity = null;
if (context.InputParameters != null && context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
entity = (Entity)context.InputParameters["Target"];
}
else
{
entity = service.Retrieve(context.PrimaryEntityName, ((Guid)context.PrimaryEntityId), new ColumnSet(true));
}
Entity opportunity = new Entity("opportunity");
string name = entity.GetAttributeValue<string>("subject");
opportunity["name"] = name;
opportunityId = service.Create(opportunity);
EntityReference accountlookup = (EntityReference)entity.Attributes["ad_sendto"];
Guid accountId = accountlookup.Id;
opportunity["parentaccountid"] = new EntityReference("account", accountId);
service.Update(opportunity);
重复一遍,它创造了机会,但它不适用于更新,有没有其他方法可以做到这一点,或者我在这里有一些错误?
它失败是因为您正在尝试更新没有设置主键 (opportunityid) 的opportunity
实体。
与其在机会创建后更新机会,为什么不在创建操作期间分配parentaccountid
呢?
var opportunity = new Entity("opportunity");
opportunity["name"] = entity.GetAttributeValue<string>("subject"); ;
opportunity["parentaccountid"] = entity.Attributes["ad_sendto"];
opportunityId = service.Create(opportunity);
为了将来参考,如果您必须更新刚刚创建的实体或任何与此相关的实体:
var opportunityToUpdate = new Entity("opportunity")
{
Id = opportunityId
};
opportunityToUpdate["parentaccountid"] = entity.Attributes["ad_sendto"];
service.Update(opportunityToUpdate);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.