3

I am using the Microsoft Dynamics Web API to write data to an entity in Microsoft Dynamics 365. When I try to do a deep insert I am receiving the error

An undeclared property 'ccseq_employeeid' 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.

Why am I receiving this error and how can I resolve the error?

JSON

{
    "ccseq_importdate" : "2017-05-28T04:00:00Z", 
    "ccseq_month" : "1", 
    "ccseq_year" : "2017", 
    "ccseq_name" : "Test", 
    "ccseq_status" : "100000000", "ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID" : 
    [ 
        { 
          "ccseq_employeeid@odata.bind": "/systemusers(6d2fd71b-32d1-dd11-a4f5-001a6449bbe7)", 
          "ccseq_clientid@odata.bind": "/ccseq_clients(663ebd00-73b9-4faf-90ed-f56bb9c2dc9b)", 
          "ccseq_navemployeeid" : "11111", 
          "ccseq_employeefirstname" : "John"
        }
    ]
}

ExpenseTransactionSet is the parent of ExpenseTransaction meaning that ExpenseTransaction has a lookup to ExpenseTransactionSet. ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID is one to many relationship. systemuser and ccseq_clients are separate entities that are lookups in ExpenseTransaction.

I've also tried the below variations on the "ccseq_employeeid@odata.bind"

  • objectid_systemuser@odata.bind
  • objectid_ccseq_employeeid@odata.bind
  • ccseq_employeeid@data.bind
  • ccseq_employeeid@odata.bind : systemusers()
  • ccseq_employeeid_systemusers@odata.bind
  • systemuserid_systemusers@odata.bind

I have seen this question and this question and tried the suggested resolutions without success.

Tim Hutchison
  • 3,483
  • 9
  • 40
  • 76

2 Answers2

3

I discovered the answer reading this thread. The correct syntax for a Navigation Property in a deep insert is to use the Child Entity Name followed by brackets with the field name. The json needs to be changed to the below

{
    "ccseq_importdate" : "2017-05-28T04:00:00Z", 
    "ccseq_month" : "1", 
    "ccseq_year" : "2017", 
    "ccseq_name" : "Test", 
    "ccseq_status" : "100000000",
    "ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID" : 
    [ 
        {
          // Next two lines are changed 
          "ExpenseTransaction[ccseq_employeeid@odata.bind]": "/systemusers(6d2fd71b-32d1-dd11-a4f5-001a6449bbe7)", 
          "ExpenseTransaction[ccseq_clientid@odata.bind]": "/ccseq_clients(663ebd00-73b9-4faf-90ed-f56bb9c2dc9b)", 
          "ccseq_navemployeeid" : "11111", 
          "ccseq_employeefirstname" : "John"
        }
    ]
}
Tim Hutchison
  • 3,483
  • 9
  • 40
  • 76
0

In the metadata document {org-url}/api/data/v8.0/$metadata, can you check the element-type of the collection-valued navigation property ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID?

Is it the same type which has ccseq_employeeid as its navigation property? If not, and the property ccseq_employeeid belongs to the derived type, you may need to annotate the navigation property object as below:

{
    "ccseq_importdate" : "2017-05-28T04:00:00Z", 
    "ccseq_month" : "1", 
    "ccseq_year" : "2017", 
    "ccseq_name" : "Test", 
    "ccseq_status" : "100000000",
    "ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID" : 
    [ 
        {
          "@odata.type": "Microsoft.Dynamics.CRM.ccseq_navemployee",
          "ccseq_employeeid@odata.bind": "/systemusers(6d2fd71b-32d1-dd11-a4f5-001a6449bbe7)", 
          "ccseq_clientid@odata.bind": "/ccseq_clients(663ebd00-73b9-4faf-90ed-f56bb9c2dc9b)", 
          "ccseq_navemployeeid" : "11111", 
          "ccseq_employeefirstname" : "John"
        }
    ]
}
Jatin Sanghvi
  • 1,928
  • 1
  • 22
  • 33
  • I'm not entirely sure what you mean here. `ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID` has an odata type of `#Microsoft.Dynamics.CRM.OneToManyRelationshipMetadata`. `ExpenseTransactionSet` is the parent of `ExpenseTransaction` which has lookups to separate entities of `systemuser` and `ccseq_clients` – Tim Hutchison Jun 29 '17 at 12:44
  • Can you try adding `"@odata.type": "Microsoft.Dynamics.CRM.ExpenseTransaction",` as first property in the `ExpenseTransaction` elements being inserted. From your comment, it seems that OData layer expects the deep-inserted elements to be of type `ExpenseTransactionSet` and does not expect them to contain property `ccseq_employeeid`. You can search for `@odata.type` in http://docs.oasis-open.org/odata/odata-json-format/v4.0/os/odata-json-format-v4.0-os.html. – Jatin Sanghvi Jul 01 '17 at 12:28
  • I received the error `A type named 'Microsoft.Dynamics.CRM.ExpenseTransaction' could not be resolved by the model. When a model is available, each type name must resolve to a valid type.` – Tim Hutchison Jul 05 '17 at 12:06