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 365 | Integration, Dataverse...
Unanswered

Dynamics 365 Xrm.Webapi throws an error: Value cannot be null. Parameter name: entityMetadata"

(1) ShareShare
ReportReport
Posted on by 2
Hey,

I have been running into an odd error when attempting to migrate from the Dynamics CRM SDK SDK.REST.js to the replacement API Xrm.WebApi. As the old client library uses deprecated enpoint /XRMServices/2011/OrganizationData.svc (See: https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/best-practices/business-logic/do-not-use-odata-v2-endpoint?tabs=odatav2)

In one use case, the library method, as shown, returns an error According to the plugin traces, and console error below the .NET Plugin runs successfully, and runs into unexpected error in client library.
CLIENT:
function executeQuery(queryString, callback) {
    try {    
        var fetchXml = "?fetchXml=<fetch mapping='logical'><entity name='{entity_name}'><filter type='and'><condition attribute='{attribute_here}' operator='eq' value='" + queryString + "'/></filter></entity></fetch>";
        window.parent.Xrm.WebApi.retrieveMultipleRecords("{entity_name}", fetchXml).then(
            (result) => {
                console.log(result)
                var ret = JSON.parse(result[0].{second_attribute});
                callback(ret);
            },
        ).catch((err) => {
            console.error(err)
            errorHandler(err);
        })  
    } catch (e) {
        errorHandler(e);
    }
}

CLIENT ERROR:
"{"errorCode":2147951877,"message":"Value cannot be null.\r\nParameter name: entityMetadata","code":2147951877,"title":"","raw":"{\"_errorCode\":-2147015419,\"_errorFault\":{\"_responseXml\":null,\"_errorCode\":0,\"_innerFault\":null,\"_callStack\":null,\"_responseText\":\"{\\\"error\\\":{\\\"code\\\":\\\"0x0\\\",\\\"message\\\":\\\"Value cannot be null.\\\\r\\\\nParameter name: entityMetadata\\\"}}\",\"_annotations\":{},\"_hasCustomerInfo\":false,\"_messages\":[\"Value cannot be null.\\r\\nParameter name: entityMetadata\"]},\"_message\":\"Value cannot be null.\\r\\nParameter name: entityMetadata\",\"_exception\":null,\"_innerError\":null,\"_errorSource\":3,\"_blockErrorReporting\":false,\"_stack\":null,\"_faultedRequestIndex\":-1,\"_clientRequestId\":\"7ce6bab7-015b-4f51-a8c0-d445e3263bed\",\"_serverResponseId\":\"0b21f478-e28b-45a1-bf1a-7a1eb7ef059f\",\"_httpStatusCode\":500,\"_retryAfter\":null,\"_date\":\"2025-02-15T13:05:37.000Z\",\"_isRequestTooLong\":false,\"message\":\"Value cannot be null.\\r\\nParameter name: entityMetadata\",\"name\":\"Error\",\"stack\":\"No stack available.\",\"__action\":{\"source\":{\"actionType\":\"modernDataSource.execute.odata.async\",\"actionStack\":\"modernDataSource.execute.odata.async\",\"contextId\":\"5ecadfdc-de49-4cb4-a464-cc24d0fcd0f3\"},\"child\":{\"actionType\":\"oData.retrieveMultiple.async\",\"actionStack\":\"oData.retrieveMultiple.async\",\"contextId\":\"52ea020a-e27d-43be-a483-3777993d437c\"}}}"}"


I have identified a piece of code that seems to trigger the error. It specifically happens when creating/handling a new Entity during Fetch Expression query and passing it to OutputParameters["BusinessEntityCollection"] in EntityCollection as shown in the code snippet below.
PLUGIN:
//NOTE: Critical information unique to implementation has been hidden. By replacing values with bracketed placeholders.                       
var e = new Entity("{entityname}");                    
e.Attributes.Add("{first_attribute}", localContext.PluginExecutionContext.PrimaryEntityId);                
e.Attributes.Add("{second_attribute}", result);
var col = new EntityCollection();
col.Entities.Add(e);
localContext.PluginExecutionContext.OutputParameters["BusinessEntityCollection"] = col;


Any ideas on how to get around this or mitigate the issue?
Thank you in advance.
 
 
PLUGINCapture.PNG
Categories:
I have the same question (0)
  • ArchitectMadhan Profile Picture
    458 on at
    Hi,
     

    Here are a few potential causes and solutions:

    1. Incorrect Entity Name: Ensure that the entity name you're using in your request is correct and matches the logical name in Dynamics 365. Entity names are case-sensitive.

    2. Metadata Cache Issue: Sometimes, the metadata cache might not be up-to-date. Try clearing the cache or refreshing the metadata.

    3. Endpoint Mismatch: Verify that you're using the correct endpoint. The error message indicates you're using the /XRMServices/2011/OrganizationData.svc endpoint, which is for the older Organization Data Service (OData v2). Consider using the Web API endpoint (/api/data/v9.0/) if possible.

    4. Missing Entity Metadata: Ensure that the entity metadata is published and available. You can check this in the Dynamics 365 customization area.

    5. Permissions Issue: Make sure that the user account making the request has the necessary permissions to access the entity metadata

    If you find this solution useful, please like it and accept it as answer.

    -ArchitectMadhan

  • DenisMT Profile Picture
    33 on at
    Hi!
     
    Keeping the implementation confidental, are you able to add traces in your plugin on your companies dev environment and can you look into them? If so, can you trace the key/values of your Entity "e" and look into the results which are returned with the entity? Perhaps this could give you some information to get to the right solution.

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 365 | Integration, Dataverse, and general topics

#1
iampranjal Profile Picture

iampranjal 41

#2
Martin Dráb Profile Picture

Martin Dráb 38 Most Valuable Professional

#3
Satyam Prakash Profile Picture

Satyam Prakash 35

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans