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)
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

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