Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Associate entites (N:N) using Web API Failed

Posted on by 170

I have the following association: 

association.png

As we can see, users can have multiple email notifications and an email notification can have multiple users.

I'm trying to associate an email notification to a user. This is how I do:

var associate = {  
      "@odata.id": "baseuri/.../systemusers(F71614E2-1EB3-E711-90F3-0050568B95ED)"
}; 

var req = new XMLHttpRequest();
    req.open("POST", encodeURI(baseuri/.../mkg_mkg_notificationemail_primaryrecipients$ref), true);
    req.setRequestHeader("Content-Type", "application/json");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.onload = function () {
        if (req.readyState == 4) {
            
        }else{
          
        }
    };
    req.send(JSON.stringify(associate));


I get the following error: 

{
  "error":{
    "code":"","message":"propertyValue (System.Uri) should be EdmEntityObjectCollection","innererror":{
      "message":"propertyValue (System.Uri) should be EdmEntityObjectCollection","type":"Microsoft.Crm.CrmException"
    }
  }
}

According to some answers on some similar posts, I reverse the entities (POST on systemusers with association of type email notification), but I get the following error:

{
  "error":{
    "code":"","message":"Invalid role specified for entity 'systemuser'in relationship 'mkg_mkg_notificationemail_primaryrecipients.Referencing'","innererror":{
      "message":"Invalid role specified for entity 'systemuser'in relationship 'mkg_mkg_notificationemail_primaryrecipients.Referencing'","type":"System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]"
    }
  }
}


Does anyone knows what is wrong ? 

Thanks in advance !

*This post is locked for comments

  • Goutham A Profile Picture
    Goutham A on at
    RE: Associate entites (N:N) using Web API Failed

    Does anyone have solution for this error?

    I am facing the same error when using "teammembership_association" with dynamics CRM web API. Please help

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Associate entites (N:N) using Web API Failed

    We are also running into an error associating N:N entities via the Web API. Most of the related forum posts we have came across suggest inverting the entities, but we are getting an error regardless of which side we treat as the parent. To rule out a one-off error with this N:N relationship, we've also tried creating a new N:N relationship between the same two entities, but get the same corresponding errors. Below are sample Web API calls and returned errors, as well as a screenshot of the relationship. Any help would be appreciated.

    For screenshot please refer to the following link: community.dynamics.com/.../264061

    Request 1:

    POST https://{orgname}.crm.dynamics.com/api/data/v8.2/str_salesorders(3A79AAFD-1AB8-E611-80E8-FC15B428BC1C)/str_strsalesorder_systemuser/$ref HTTP/1.1

    OData-Version: 4.0

    OData-MaxVersion: 4.0

    {"@odata.id":"https://{orgname}.crm.dynamics.com/api/data/v8.2/systemusers(5C44C50A-5FAC-4150-8BDB-D1950A412438)"}

    Response 1:

    HTTP/1.1 500 Internal Server Error

    OData-Version: 4.0

    {

     "error":{

       "code":"","message":"propertyValue (System.Uri) should be EdmEntityObjectCollection","innererror":{

         "message":"propertyValue (System.Uri) should be EdmEntityObjectCollection","type":"Microsoft.Crm.CrmException","stacktrace":"   at Microsoft.Crm.CrmException.Assert(Boolean condition, String message)\r\n   at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmEntityTypeConverter.SetNavigationPropertyToXrmEntity(Entity entity, EntityMetadata entityMetadata, IEdmProperty edmProperty, EntityRelationship entityRelationship, Object propertyValue, Nullable`1 role)\r\n   at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmEntityTypeConverter.ConvertToCrmTypeInternal(EdmEntityObject edmTypeValue)\r\n   at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmTypeConverterBase`2.ConvertToCrmType(Object edmTypeValue)\r\n   at Microsoft.Crm.Extensibility.OData.EdmTypeConverter.ConvertToCrmEntity(EdmEntityObject edmEntity, EntityReference entityReference)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.UpdateResourceProperty(CrmODataExecutionContext context, String edmEntityName, String entityKeyValue, String propertyName, Object edmPropertyValue)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.UpdateResourceNavigationPropertyReference(CrmODataExecutionContext context, String edmEntityName, String entityKeyValue, String navigationPropertyName, CrmEdmEntityReference edmPropertyReference)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.UpdateNavigationRefInternal(String entityName, String key, String navigation, Uri link)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.PostNavigationRef(String entityName, String key, String navigation, Uri link)\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"

       }

     }

    }

    -----------

    Request 2:

    POST https://{orgname}.crm.dynamics.com/api/data/v8.2/systemusers(5C44C50A-5FAC-4150-8BDB-D1950A412438)/str_strsalesorder_systemuser/$ref HTTP/1.1

    OData-Version: 4.0

    OData-MaxVersion: 4.0

    {"@odata.id":"https://{orgname}.crm.dynamics.com/api/data/v8.2/str_salesorders(3A79AAFD-1AB8-E611-80E8-FC15B428BC1C)"}

    Response 2:

    HTTP/1.1 400 Bad Request

    OData-Version: 4.0

    {

     "error":{

       "code":"","message":"Invalid role specified for entity 'systemuser'in relationship 'str_strsalesorder_systemuser.Referencing'","innererror":{

         "message":"Invalid role specified for entity 'systemuser'in relationship 'str_strsalesorder_systemuser.Referencing'","type":"System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]","stacktrace":"   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Associate(EntityReference entityReference, Relationship relationship, EntityReferenceCollection relatedEntities, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.Associate(EntityReference entityReference, Relationship relationship, EntityReferenceCollection relatedEntities)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.UpdateResourceNavigationPropertyReference(CrmODataExecutionContext context, String edmEntityName, String entityKeyValue, String navigationPropertyName, CrmEdmEntityReference edmPropertyReference)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.UpdateNavigationRefInternal(String entityName, String key, String navigation, Uri link)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.PostNavigationRef(String entityName, String key, String navigation, Uri link)\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"

       }

     }

    }

  • Hubert Solecki Profile Picture
    Hubert Solecki 170 on at
    RE: Associate entites (N:N) using Web API Failed

    Thanks, i've already tried to swap the entities but does not work for me...

  • Emre GULCAN Profile Picture
    Emre GULCAN 2,379 on at
    RE: Associate entites (N:N) using Web API Failed

    Hi,

    Not sure but maybe this can helps you github.com/.../1

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans