Loading...

Basic payload to create BULK DELETE job using web api

Basic payload to create BULK DELETE job using web api

I was investigating one issue from Stack overflow post and assisting Chris request in LinkedIn chat around the same topic. Basically the payload for creating BULK DELETE job using web api is cumbersome and trying all sort of options to get it done.

Finally able to sort out using CRM REST Builder, and some trial and errors techniques.

The worked payload will work like below:

var parameters = {};
var queryset1 = {
EntityName: "account",
ColumnSet: {
AllColumns: true
},
Distinct: false,
};

queryset1["@odata.type"] = "Microsoft.Dynamics.CRM.QueryExpression";
parameters.QuerySet = [queryset1];
parameters.JobName = "arun test";
parameters.SendEmailNotification = false;
var torecipients1 = {};
torecipients1.activitypartyid = "00000000-0000-0000-0000-000000000000"; //Delete if creating new record
torecipients1["@odata.type"] = "Microsoft.Dynamics.CRM.activityparty";
parameters.ToRecipients = [torecipients1];
var ccrecipients1 = {};
ccrecipients1.activitypartyid = "00000000-0000-0000-0000-000000000000"; //Delete if creating new record
ccrecipients1["@odata.type"] = "Microsoft.Dynamics.CRM.activityparty";
parameters.CCRecipients = [ccrecipients1];
parameters.RecurrencePattern = "FREQ=DAILY;";
parameters.StartDateTime = JSON.stringify(new Date("05/07/2021 13:30:00").toISOString());
parameters.RunNow = false;

var bulkDeleteRequest = {
QuerySet: parameters.QuerySet,
JobName: parameters.JobName,
SendEmailNotification: parameters.SendEmailNotification,
ToRecipients: parameters.ToRecipients,
CCRecipients: parameters.CCRecipients,
RecurrencePattern: parameters.RecurrencePattern,
StartDateTime: parameters.StartDateTime,
RunNow: parameters.RunNow,

getMetadata: function() {
return {
boundParameter: null,
parameterTypes: {
"QuerySet": {
"typeName": "Collection(mscrm.QueryExpression)",
"structuralProperty": 4
},
"JobName": {
"typeName": "Edm.String",
"structuralProperty": 1
},
"SendEmailNotification": {
"typeName": "Edm.Boolean",
"structuralProperty": 1
},
"ToRecipients": {
"typeName": "Collection(mscrm.activityparty)",
"structuralProperty": 4
},
"CCRecipients": {
"typeName": "Collection(mscrm.activityparty)",
"structuralProperty": 4
},
"RecurrencePattern": {
"typeName": "Edm.String",
"structuralProperty": 1
},
"StartDateTime": {
"typeName": "Edm.DateTimeOffset",
"structuralProperty": 1
},
"RunNow": {
"typeName": "Edm.Boolean",
"structuralProperty": 1
}
},
operationType: 0,
operationName: "BulkDelete"
};
}
};

Xrm.WebApi.online.execute(bulkDeleteRequest).then(
function success(result) {
if (result.ok) {
var results = JSON.parse(result.responseText);
}
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);

If you are facing errors, like "The Entity xxxx does not support Synchronous Bulk Delete" then "RunNow = false" is the fix.

Another tricky part is RecurrencePattern = "FREQ=DAILY;"

The worst part is "QuerySet" so it should be QUERY EXPRESSION.

Able to sort out like above for without condition criteria to delete all Accounts.


Published on:

Learn more
Arun Vinoth @ Dynamics
Arun Vinoth @ Dynamics

Share post:

Related posts

Dynamics 365 and Power Platform 2025 release Wave 2 - My Picks

Its time again! Microsoft release plans for 2025 Wave 2 time and nice additions and announcements on the list of both Dynamics 365 and Power P...

11 months ago

Feature taken out - Form footer

In this mini-series, the author revisits retired features, and this time they look at the Form footer feature. The feature was removed as part...

3 years ago

Feature taken out - Breadcrumbs

Microsoft has removed the Breadcrumbs feature, which was previously present in Dynamics and heavily used by business users. According to relea...

3 years ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.