Dynamics 365 incidents and contacts deep insert

142 views Asked by At

I am trying the deep insert for incidents and contacts entities using the OData Web API. When I create these records separately (of course association is needed), there is no issue.

When I tried deep insert it didn't work.

This way of separate insertion has no issue.

JObject contact = new JObject{
    { "firstname", "Yvonne" },
    { "lastname", "McKay (sample)" },
    { "jobtitle", "Coffee Master" },
    { "annualincome", 45000 }
};

Uri contact1Uri = svc.PostCreate("contacts", contact);

JObject incident1 = new JObject
{
    { "title", "Sithu Test case" },
    {  "description", "case" },
    { "[email protected]", "/contacts(7c8742cd-86c4-ec11-a7b5-002248567570)" },
};

Uri incident1Uri = svc.PostCreate("incidents", incident1);

When I tried like following

JObject incident = new JObject{
    { "title","Case 1 for Susanna Stubberod"},
    { "description","Task 1 for Susanna Stubberod description"},
    { "customerid_contact", new JObject{ 
        { "firstname","Susanna"},
        { "lastname","Stubberod (sample)"},
        { "jobtitle","Senior Purchaser"},
        { "annualincome", 52000},
    }
}};

Uri incident1Uri = svc.PostCreate("incidents", incident);

It returned the error:

You should specify a contact or account.

Please help me find the issue.

1

There are 1 answers

1
James Wood On

I suspect the error is a combination of two factors:

  1. Dynamics enforces that all incident records must have a primary account or contact. This is enforced at the application level, I don't believe there is any way around this.
  2. I suspect when performing a deep insert, Dynamics creates the outer object first and then creates the inner, deeper, objects.

This means Dynamics attempts to create the incident first, without a contact, which causes an error. I'm not sure there is anything you can do about this, apart from not doing a deep insert.