新しいエンティティを作成しました。カスタムワークフローアクティビティで作成したレコードを更新する-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);
繰り返すように、それは機会を作成し、それは更新のために動作しません、これを行うには、他の方法があり、または私はここに多少の誤差がありますか?
'機会[ "parentaccountid"] = entity.Attributes [" ad_sendtoを"];' 'service.Update(opportunityToUpdate);' 最後の2行は、更新のために 'opportunity [" parentaccountid "]'または 'opportunityToUpdate [" parenaccountid "]'を意味しましたか? –
あなたは正しいです、コピーの貼り付けエラー、答えを更新しました。 – dynamicallyCRM