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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)
Suggested Answer

CRUD Request using executeMultiple() in Javascript

(0) ShareShare
ReportReport
Posted on by 4

Hello,

I'm supposed to create a JS-Ribbon-Button that deletes a ton of records. Since there is no Xrm.WebApi.deleteMultiple() method, I tried doing it with executeMultiple.

Request object code is:

deleteRequest = function (entityName, recordId) {
        this.EntityName = entityName;
        this.RecordId = { "guid": recordId };
        this.getMetadata = function() {
            return {
                boundParameter: undefined,
                operationName: 'Delete',
                operationType: 2,
                parameterTypes: {
                    'EntityName': {
                        'typeName': "Edm.String",
                        'structuralProperty': 1
                    },
                    'RecordId': {
                        'typeName': "Edm.Guid",
                        'structuralProperty': 1
                    }
                }
            }
        }
}

For testing purposes I was using static values and creating an array of request objects from that:

async function deleteMultipleRecords() {

    try {

        let reqObj1 = new deleteRequest('invoice', '4842dec3-84c9-e911-a839-000d3ab18d29')

        let reqObj2 = new deleteRequest('invoice', 'c552f5c3-84c9-e911-a833-000d3ab182a9')

        let reqObjArr = [reqObj1, reqObj2]


        res = await Xrm.WebApi.online.executeMultiple(reqObjArr)
        console.log(res)

    } catch (error) {
        console.log(`${error.name}: ${error.message}`)
    }
}

}

I am getting a not very helpful error in console:

An error has occured. Try this action again. If the problem continues, check the Microsoft Dynamics CRM Community for solutions or contact your organization's Microsoft Dynamics CRM Administrator. Finally, you can contact Microsoft Support.

My request object must be wrong, but I don't see how? Anyone know where I made a mistake? I would really appreciate the help.

*This post is locked for comments

I have the same question (0)
  • rthompson Profile Picture
    1,532 on at

    Please post the error message that you are getting.

    I would not suggestion deleting a batch of records in a javascript.  Its okay for a single record delete.

    I would creating an action that would trigger a plugin on the entity postoperation to handle the deletion of the records on the server and not on the client.

  • Thomas Schick Profile Picture
    4 on at

    Hello rthompson,

    thank you for your reply. I posted the error message up above. That's really all I'm getting.

    I was hoping to avoid having to learn C# to write a plug-in for this problem - but if you tell me this is the best (or only) way, I will probably have to...?

  • Suggested answer
    Andrej_J Profile Picture
    2 on at
    hi,

    you need to delete "EntityReference" not the "Entity"
     
    your request should look like
     
    deleteRequest = function (entityName, recordId) {
        this.entityReference = {
            entityType: entityName,
            id: recordId
        }
        this.getMetadata = function() {
            return {
                boundParameter: undefined,
                operationName: 'Delete',
                operationType: 2,
                parameterTypes: {}
            }
        }
    }
     
    you dont even need to specify parameterTypes
     
    regards
     
    Andrej

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans