[英]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.