web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Unable to update/delete Teams using web api

(0) ShareShare
ReportReport
Posted on by

Hi I am trying to update/delete a record in Teams entity in Webapi using its Primary Key ownerid (see here https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/team?view=dynamics-ce-odata-9 ) but getting the error: "Invalid EntityKey Operation performed : Entity team does not contain an attribute named ownerid". This error seems vague as ownerid is infact the primary key for Teams entity as mentioned in the entityReference link and also in the call from $metadata. The exact network call I am trying is of the type 

PATCH [organization URI]/api/data/v9.0/teams(ownerid=<ValidGUIDHere) and

DELETE [organization URI]/api/data/v9.0/teams(ownerid=<ValidGUIDHere) and both are returning this error. Isn't this a bug in Microsoft WebApi implementation as ownerId is a PK? The same query works when I try to update account/contact entity i.e PATCH [organization URI]/api/data/v9.0/accounts(accountid=<ValidGUIDHere)

The request formation is same as the one used with updates/deletes through alternate keys see https://www.inogic.com/blog/2016/10/retrieve-update-and-delete-record-using-alternate-key-in-dynamics-crm-web-api/ .

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    The exact error message returned as response is as follows:

    {"error":{"code":"0x8006088f","message":"Invalid EntityKey Operation performed : Entity team does not contain an attribute named ownerid","innererror":{"message":"Invalid EntityKey Operation performed : Entity team does not contain an attribute named ownerid","type":"System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]","stacktrace":"   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Update(Entity entity, InvocationContext invocationContext, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, Boolean checkForOptimisticConcurrency, Dictionary`2 optionalParameters)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.Update(Entity entity, UpdateOption updateOption)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.UpdateEdmEntity(CrmODataExecutionContext context, String edmEntityName, String entityKeyValue, EdmEntityObject entityObject)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.PatchEntityImplementation(String& entityName, String key, EdmEntityObject entityDelta)\r\n   at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func, IEnumerable`1 additionalCustomProperties)\r\n   at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)\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.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.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.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.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"}}}

  • BadrinathB Profile Picture
    970 on at

    Hi,

    Did you check if your teams own any records. First try to assign the records to different team then you try. I hope you might have verified this but just a quick look.

  • crm development Profile Picture
    870 on at

    Hi Kritisha,

    "teamid" is the Primary Key Attribute of Team Entity whereas "ownerid" is Unique identifier for the Owner: systemuserid or teamid.

    Change your code as per below and try again.

    PATCH [organization URI]/api/data/v9.0/teams(ValidTeamGUID)

    DELETE [organization URI]/api/data/v9.0/teams(ValidteamGUID)

    Hope this helps.

    Thanks,

    Anand

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi kritisha,

    Try with this -

    // UPDATE TEAM

           var entity = {};
            entity.description = "DAS";
    
            var req = new XMLHttpRequest();
            req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/teams(6BB51D12-63F1-E811-A963-000D3A18BA6D)", true);
            req.setRequestHeader("OData-MaxVersion", "4.0");
            req.setRequestHeader("OData-Version", "4.0");
            req.setRequestHeader("Accept", "application/json");
            req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            req.onreadystatechange = function() {
                if (this.readyState === 4) {
                    req.onreadystatechange = null;
                    if (this.status === 204) {
                        //Success - No Return Data - Do Something
                    } else {
                        Xrm.Utility.alertDialog(this.statusText);
                    }
                }
            };
            req.send(JSON.stringify(entity));
    
    
    

    // DELETE TEAM var req = new XMLHttpRequest(); req.open("DELETE", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/teams(6BB51D12-63F1-E811-A963-000D3A18BA6D)", true); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.onreadystatechange = function() { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 204 || this.status === 1223) { //Success - No Return Data - Do Something } else { Xrm.Utility.alertDialog(this.statusText); } } }; req.send();


  • Community Member Profile Picture
    on at

    Hi Anand

    ownerid is the primary key attribute of the Teams entity as mentioned in the official entity link  https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/team?view=dynamics-ce-odata-9 . In our CRM code we are having a generic request formation same for PK and AK where we specify keyfieldName=GUID for the unique identifier request. Plus the same request works for account entity i.e. PATCH [organization URI]/api/data/v9.0/accounts(accountid=<ValidGUIDHere) then why not for Teams entity. Infact I am seeing similar error in SystemUser entity as well.

  • Community Member Profile Picture
    on at

    yes that is not the issue.

  • Suggested answer
    crm development Profile Picture
    870 on at

    Hi Kritisha,

    You can check Primary key in CRM customization. Please navigate to Settings- Customization- Default Solution - Team/User Entity- Fields.

    Also, you can create Web API using REST builder which will give you more clarification about code (Code suggested by Gautam).

    I truly understand your concern about blog, but it is always good idea to cross verify in system.

    Team Entity- Primary Key: teamid

    8463.Untitled1.png

    User Entity- Primary Key: systemuserid

    8463.Untitled1.png

    Hope this helps.

    Thanks,

    Anand

  • Community Member Profile Picture
    on at

    Hi Anand, thanks for your response but when I tried the following query: DELETE [organization URI]/api/data/v9.0/teams(teamid=ValidteamGUID)] even that failed with error: Bad Request - Error in query syntax. This clearly means that for teams entity updates/deletes cant have any Primary key field name being passed in the query URL whether it is teamid or ownerid.Only requests of type DELETE [organization URI]/api/data/v9.0/teams(ValidteamGUID) would work. In our CRM solution however we want to pass the key field name as well for better request tracking.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans