ssisを使用して価格設定承認製品の名前フィールドを更新する必要があります。これは私のコードインスクリプトコンポーネントです。ssisスクリプトコンポーネントを使用してDynamics CRMの価格設定承認製品(カスタムエンティティ)の名前フィールドを更新する方法
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
Guid AppProductLookup = new Guid();
AppProductLookup = getAppProductId(Row.Name, ref organizationservice);
Entity AppProductEnt = new Entity("new_ticketproduct");
ColumnSet columns = new ColumnSet(true);
columns = new ColumnSet(new String[] { "new_name"});
AppProductEnt = organizationservice.Retrieve(AppProductEnt.LogicalName, AppProductLookup, columns);
AppProductEnt["new_name"] = Row.Name;
organizationservice.Update(AppProductEnt);
}
public Guid getAppProductId(string name, ref IOrganizationService service)
{
Guid AppProductId = Guid.Empty;
QueryExpression AppProduct = new QueryExpression { EntityName = "new_ticketproduct", ColumnSet = new ColumnSet(true) };
AppProduct.Criteria.AddCondition("new_name", ConditionOperator.Equal, name);
EntityCollection AppProductRetrieve = service.RetrieveMultiple(AppProduct);
if (AppProductRetrieve != null && AppProductRetrieve.Entities.Count > 0)
{
AppProductId = AppProductRetrieve.Entities[0].GetAttributeValue<Guid>("new_ticketproductid");
}
return AppProductId;
}
しかし、私は例外があります:エンティティ参照はIDとキー属性を空にすることはできません。しかし、crmの私の名前フィールドはテキストフィールドです。私はまた私のブレークポイントは、このコードif (AppProductLookup != Guid.Empty)
をスキップチェック `
if (AppProductLookup != Guid.Empty)
{
AppProductEnt = organizationservice.Retrieve(AppProductEnt.LogicalName, AppProductLookup, columns);
AppProductEnt["new_name"] = Row.Name;
organizationservice.Update(AppProductEnt);
}
else
{
//AppProductEnt["new_name"] = Row.Name;
//organizationservice.Create(AppProductEnt);
}
を使用します。したがって、私はエラーはありませんが、それは私が望むものではありません。 何が間違っているのか分かりません。だから私はここで少し失われている。これに代わる方法として
あなたのコードは何をしようとしていますか?名前に基づいてレコードを検索していて、名前フィールドを検索に使用した値に更新しているようです。また、「if(!AppProductEnt.Contains( "new_ticketproductid"))」という行は、「一致するレコードが見つからない場合」を意味します。これはあなたが意図したものですか? –
自分のコードを編集しました。私が欲しいのは、GUIDのチェックに基づいてCRMに名前が既に存在する場合、新規作成ではなく名前を更新したいのです。だからすでに私がやったことは、CRMの名前レコードの既存のGUIDを取得し、GUIDに基づいて更新しようとすることです。しかし、それは私が望むように働いていない。 – xChaax
まだ明確ではありません。このコードは、name = blaaのレコードを検索し、name = blaaに設定しています。どうして?また、getAppProductId()の呼び出しでGuid.Emptyが返された場合、更新するレコードがないためUpdate()の呼び出しは失敗します。 –