12

この質問は、Microsoft Dynamics CRM 2015に関連しており、APIを使用しています。APIを使用してMicrosoft Dynamics CRMの連絡先エンティティに注釈を作成

私は連絡先エンティティを作成します。私はパネルにログインした後

POST [organization URI]/api/data/contacts 
Content-Type: application/json; charset=utf-8 
Accept: application/json 
{ 
    "emailaddress1": "[email protected]", 
} 

それは動作しますが、私は、新しいレコードを参照してください。 そして、私はAPIを通してそれを呼び出すことができます。

[organization URI]/api/data/contacts(f76e4e7c-ea61-e511-80fd-3863bb342b00) 
{ 
    "@odata.context":"[organization URI]/api/data/$metadata#contacts/$entity", 
    "@odata.etag":"W/\"460199\"", 
    ... 
    "contactid":"f76e4e7c-ea61-e511-80fd-3863bb342b00", 
    "emailaddress1":"[email protected]", 
    .... 
} 

私がやりたい次のことは、その連絡先に関連付けられている注釈レコードを追加することです。 私が呼んguide次のとおりです。

POST [organization URI]/api/data/annotations 
Content-Type: application/json; charset=utf-8 
Accept: application/json 
{ 
    "notetext": "TEST", 
    '[email protected]': 'contacts(f76e4e7c-ea61-e511-80fd-3863bb342b00)' 
} 

しかし、それは400エラーを返します:私が呼ぶとき

An undeclared property 'contact' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.

POST [organization URI]/api/data/annotations 
Content-Type: application/json; charset=utf-8 
Accept: application/json 
{ 
    "notetext": "TEST", 
} 

新しいエンティティがなく、連絡に関係なく、作成されます。

このPOSTリクエストを正しく構成するにはどうすればよいですか?私はここで何が欠けていますか? 私は、[email protected]は何とか違ったものを提示しなければならないと思っています。私は試しました。[email protected][email protected][email protected] - 効果はありません。

アイデア?

+0

は、なぜあなたは、Web APIプレビューではなくRESTエンドポイントを使用していますか? –

+0

コードは '' [email protected] "でなければなりません:"/contacts(f76e4e7c-ea61-e511-80fd-3863bb342b00) "連絡先と引用符の前の'/'に注意してください。 –

+0

@GuidoPreite Iエラーメッセージは次のとおりです。 'ペイロードにプロパティ注釈しか持たないプロパティ値 'objectid'は、プロパティ値が 'Edm.Guid'型であると宣言されています。 ODataでは、ナビゲーションプロパティと名前付きストリームのみが、値を持たないプロパティとして表現できます。 – maicher

答えて

5

私はこの作業を見つけましたが、2つの要求できました:

POST [organization URI]/api/data/annotations 
Content-Type: application/json; charset=utf-8 
Accept: application/json 
{ 
    "notetext": "TEST" 
} 

POST [organization URI]/api/data/contacts(f76e4e7c-ea61-e511-80fd-3863bb342b00)/Contact_Annotation/$ref 
Content-Type: application/json; charset=utf-8 
Accept: application/json 
{ 
    "@odata.id": "[organization URI]/annotations(annotation_id_from_first_request)" 
} 

編集:

annotation_id_from_first_request値が取得され、フォームの最初のリクエストの応答を。

+1

annotation_id_from_first_requestはどのように知っていますか? –

+0

最初の要求の応答からです。 – maicher

11

[email protected]の代わりに[email protected]を使用する必要があります。 documentationに単一値のナビゲーションプロパティの下で見て、プロパティのリストを取得するには

"[email protected]": "/contacts(f76e4e7c-ea61-e511-80fd-3863bb342b00)" 

:この結果がでています。

+1

これは、1回の呼び出ししか使用しないため、受け入れられた応答より優れています。私は "_contact"(または類似のもの)の追加を推測していますが、現在のレコードが親レコードか子レコードかによって異なります。 – zabby

+1

これは、これは、さまざまなエンティティを参照できるノートのフィールドに固有のものだからだと思います。したがって、_contactは、それを設定するエンティティ(フィールドに関するメモの場合は常にobjectid_entityname)に依存します。 – Justin

4

私が作成してリンクするため、このC#コードを使用しています(Task.Awaitものはない非常に賢いので、...注意してください):

 dynamic testAno = new ExpandoObject(); 
     testAno.NoteText = "Hello World!"; 
     testAno.Subject = "Note Subject"; 

     dynamic refAccount = new ExpandoObject(); 
     refAccount.LogicalName = "account"; 
     refAccount.Id = "003CCFC2-4012-DE11-9654-001F2964595C"; 

     testAno.ObjectId = refAccount; 
     testAno.ObjectTypeCode = refAccount.LogicalName; 

     var demo = JsonConvert.SerializeObject(testAno); 

     HttpContent content = new StringContent(demo, Encoding.UTF8, "application/json"); 

     var handler = new HttpClientHandler { UseDefaultCredentials = true }; 

     HttpClient client = new HttpClient(handler); 
     var test = client.PostAsync(new Uri("http://crm/.../XRMServices/2011/OrganizationData.svc/AnnotationSet"), content).Result; 

はJSONはこのように見ている:

{"NoteText":"Hello World!", 
"Subject":"Note Subject", 
"ObjectId": {"LogicalName":"account", 
       "Id":"003CCFC2-4012-DE11-9654-001F2964595C"} 
,"ObjectTypeCode":"account"} 
4

は、この答えは、Web APIの利用に適用されます。

参照プロパティは大文字を使用して定義されている場合は、更新や挿入のプロパティに大文字を使用する必要があります。プライマリエンティティのプロパティリストのスキーマ名を確認します。

"[email protected]":"/accounts(f76e4e7c-ea61-e511-80fd-000000000000)" 

大文字:

は、アカウントのエンティティを参照してmyprefix_entityと呼ばれるエンティティを持っていると言うことができます、そしてあなたはそれをAccountの名前、およびスキーマ名がmyprefix_AccountIdになった、あなたはとしてそれを参照する必要がありますAと大文字のIがmyprefix_AccountIdの場合は、スキーマ名が定義されている方法です。

4

パート1:
MSDN参考:コードの下Deep Insert

You can create entities related to each other by defining them as navigation properties values. This is known as deep insert. As with a basic create, the response OData-EntityId header contains the Uri of the created entity. The URIs for the related entities created aren’t returned.

は、(1)アカウントを作成+関連付ける第一連絡先(2)を作成し、(3)&准機会を作成し、作成することです+関連付けるタスク(4)

POST [Organization URI]/api/data/v8.2/accounts HTTP/1.1 
Content-Type: application/json; charset=utf-8 
OData-MaxVersion: 4.0 
OData-Version: 4.0 
Accept: application/json 

{ 
"name": "Sample Account", 
"primarycontactid": 
{ 
    "firstname": "John", 
    "lastname": "Smith" 
}, 
"opportunity_customer_accounts": 
[ 
    { 
     "name": "Opportunity associated to Sample Account", 
     "Opportunity_Tasks": 
     [ 
     { "subject": "Task associated to opportunity" } 
     ] 
    } 
] 
} 

パート2:
注釈を連絡先に関連付けるには、以下の構文を使用します。

note["[email protected]"] = "/contacts(C5DDA727-B375-E611-80C8-00155D00083F)"; 

パート3 SO link & blog

を参照してください:最後の要求から応答で作成されたレコードIDを取得するには

、次のことができます。annotation_id_from_first_requestに関する別の答えにあなたのコメントへの
回答以下のように解析します。

   //get Response from Created Record 
       entityIdWithLink = XMLHttpRequest.getResponseHeader("OData-EntityId"); 

       //get EntityId from ResponseHeader of Created Record 
       getEntityId = entityIdWithLink.split(/[()]/); 
       getEntityId = getEntityId[1]; 

することはできread more

You can compose your POST request so that data from the created record will be returned with a status of 201 (Created).
To get this result, you must use the return=representation preference in the request headers. To control which properties are returned, append the $select query option to the URL to the entity set.
The $expand query option will be ignored if used. When an entity is created in this way the OData-EntityId header containing the URI to the created record is not returned

Note: This capability was added with December 2016 update for Dynamics 365

MSDNリファレンス:Create with data returned

関連する問題