Skip to main content

Notifications

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

  • Suggested answer
    Andrej_J Profile Picture
    2 on at
    CRUD Request using executeMultiple() in Javascript
    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
  • Thomas Schick Profile Picture
    4 on at
    RE: CRUD Request using executeMultiple() in Javascript

    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...?

  • rthompson Profile Picture
    1,532 on at
    RE: CRUD Request using executeMultiple() in Javascript

    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.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,118 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans