SBX - Search With Button

SBX - Forum Post Title

CRM Web API error 500 (Internal Server Error)

Microsoft Dynamics CRM Forum

Sergey Dubak asked a question on 9 Nov 2018 4:55 AM

Question Status

Suggested Answer

Hi!

I'm trying to add a user to a team using CRM Web API from python script but was thrown with 500 response code (Internal Server Error).

In "C:\Program Files\Microsoft Dynamics CRM\Trace\*-CRMWeb-*.log" file several errors appeared:
- Failed to log the audit record into the database Procedure or function 'p_InsertMultipleAuditRows' expects parameter '@audituseradditionalinfo', which was not supplied. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
- Crm Exception: Message: Failed to insert audit record, ErrorCode: -2147220970, InnerException: System.Data.SqlClient.SqlException (0x80131904): Procedure or function 'p_InsertMultipleAuditRows' expects parameter '@audituseradditionalinfo', which was not supplied.
- Web Service Plug-in failed in SdkMessageProcessingStepId: {1CB0FEB7-5A25-4032-8AC9-307C808580AA}; EntityName: team; Stage: 25; MessageName: AddMembers; AssemblyName: Microsoft.Crm.AuditRelationsPlugin, Microsoft.Crm.Audit, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35; ClassName: Microsoft.Crm.AuditRelationsPlugin; Exception: Unhandled Exception: Microsoft.Crm.CrmException: Failed to insert audit record
- MessageProcessor fail to process message 'AddMembers' for 'team'.
- System.Data.SqlClient.SqlException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #67261A37: System.Data.SqlClient.SqlException (0x80131904): Procedure or function 'p_InsertMultipleAuditRows' expects parameter '@audituseradditionalinfo', which was not supplied.
- {"Error":{"InnerError":null,"Message":"FaultException`1: Failed to insert audit record"}}

Part of the script:
url = '<CRM_LINK>/api/data/v8.1/teams(<TEAM_ID>)/Microsoft.Dynamics.CRM.AddMembersTeam'
data = {
    'Members': [
        {
            'ownerid': <USER_ID>,
            '@odata.type': 'Microsoft.Dynamics.CRM.systemuser'
        }
    ]
}


We are using Microsoft Dynamics CRM 2016 8.1.0.359 version.

Reply
Anand Wani responded on 9 Nov 2018 9:01 AM
My Badges

Hi,

Would you give a try with below code which is working fine in my end.

var parameters = { Members: [{ "ownerid": <USER_ID> }] };

var req = new XMLHttpRequest();

req.open("POST", <CRM_URL> + "/api/data/v8.1/teams(<TEAM_ID>)/Microsoft.Dynamics.CRM.AddMembersTeam", 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(parameters));

Reply
Ravi Kashyap responded on 9 Nov 2018 9:58 AM

Hi Goutam,

The link you have shared is broken but I am pretty sure that WEB API was introduced in CRM 2016 which is v8.0. You can verify this in the Rest Builder tool wherein you can create WEB API request for 8.0, 8.1 & 8.2 as well.

Hope this helps.

Reply
Goutam Das responded on 9 Nov 2018 11:50 AM

Thanks Ravi, for rectifying this, You are right.Actually I followed wrong reference .

Reply
Ravi Kashyap responded on 10 Nov 2018 12:01 AM

Hi Goutam,

That's the new enhancement on the existing WEB API which are introduced in 8.2, to be specific, returning entity data with create/ update using return=representation preference in the header of the request.

docs.microsoft.com/.../gg309589(v=crm.8)

Hope this helps.

Reply
Andrew Butenko responded on 11 Nov 2018 8:42 AM
Suggested Answer

Sergey,

It looks like your code is correct. The problem is in frontend and I don't think you can fix it by yourself. I would recommend to open a ticket with Microsoft.

Reply
Andrew Butenko responded on 11 Nov 2018 8:42 AM
Suggested Answer

Sergey,

It looks like your code is correct. The problem is in frontend and I don't think you can fix it by yourself. I would recommend to open a ticket with Microsoft.

Reply

SBX - Two Col Forum

SBX - Migrated JS