Announcements
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
deleteRequest = function (entityName, recordId) {
this.entityReference = {
entityType: entityName,
id: recordId
}
this.getMetadata = function() {
return {
boundParameter: undefined,
operationName: 'Delete',
operationType: 2,
parameterTypes: {}
}
}
}
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...?
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.
André Arnaud de Cal...
294,118
Super User 2025 Season 1
Martin Dráb
232,866
Most Valuable Professional
nmaenpaa
101,158
Moderator