2011-12-09 3 views
1

レコードを作成するためのプラグインを作成しましたが、次の問題に直面しています。MS CRM 2011レコードを作成してGUIDを取得

私は2つのエンティティを持っています。エンティティ1とエンティティ2。 Entity2はEntity1とのn-1の関係を持ち、Entity1のLookupフィールドも持っています。私のプラグインのコードでは、Entity1レコードを作成し、その後、Entity1のちょうど作成されたレコードで満たされたLookupフィールド(Entity1への)でEntity2レコードを作成したいと思う。しかし、私はエラーが発生しました。私のコードは次のようになります:

Entity entity1 = new Entity("new_entity1"); 
//Here I'm filling my entity1's fields 
Guid entity1Id = service.Create(entity1); 

Entity entity2 = new Entity("new_entity2"); 
//Here I'm filling my entity2's fields 
entity2 ["new_entity1id"] = new EntityReference("new_entity1",entity1Id); 

service.Create(entity2); 

私は本当に問題を認識することはできません。私はプラグインのコードが終了したときにすべてが作成されると仮定しているため、Entity2レコードを作成する時点でEntity1レコードは作成されませんが、それは私の前提です。

助けがあれば助かります。

エラーメッセージ:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxx]]: An error occured in the AccountCreateHandler plug-inDetail: <OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts"> <ErrorCode>-2147220891</ErrorCode> <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic"> 
    <KeyValuePairOfstringanyType> 
     <d2p1:key>OperationStatus</d2p1:key> 
     <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">0</d2p1:value> 
    </KeyValuePairOfstringanyType> </ErrorDetails> <Message>An error occured in the AccountCreateHandler plug-in</Message> <Timestamp>2011-12-09T14:17:22.2773373Z</Timestamp> <InnerFault i:nil="true" /> <TraceText> 

[Execute_Buchen: Execute_Buchen.Class1] [dc2f71e8-b216-e111-b59f-00155d0a3339: Execute_Buchen.Class1: Update of new_entity0 START:IPlugin.Execute 

</TraceText> </OrganizationServiceFault> 
+0

あなたは例外を投稿できますか?あなたが持っているものは正しいです。プラグインは同期して実行されます(プラグイン登録ツールでチェックされていれば提供されます)ので、まずエンティティ1を作成し、次にGUIDを持つエンティティ2を作成します – Chris

+0

正しいエンティティ名とフィールドを使用していますか?それはあなたが投稿したコードと比較して 'new_entity0'の更新と言いますか? – Chris

+0

はい私はこのpostinのために "new_entity0"自分自身に名前を変更しました。これは私の質問の実体(entity1またはentity2)でもありません。事実は、私が行を削除すると: entity2 ["new_entity1id"] =新しいEntityReference( "new_entity1"、entity1Id); 私の質問に投稿されたレコードはもちろん、エンティティ2レコードの空のlookupfieldで作成される – user1016077

答えて

2

ではなく、このようにそれをやってみてください。

entity2.Attributes.Add("new_entity1id",new EntityReference("new_entity1",entity1Id)); 

上記を試してもまだ例外がスローされている場合は、2つしか考えられません。ラインで

entity2 ["new_entity1id"] = new EntityReference("new_entity1",entity1Id);

どちらのnew_entity1idは異なるエンティティにルックアップし、EntityReferenceあなたが投げている作成、保存しようとしているフィールドを検索entity2

または

の間違ったフィールド名です例外。

+0

2つの理由のいずれかが例外の原因として私には良い候補のように見える – glosrob

関連する問題