When I copy data from prod to a sandbox I usually go through a series of bulk deletions to save space. While I know I could stack a bunch of Power Automate Job I have run into throttling issues.
Is there a good way to import or create these jobs through Power Automate? I think one option I could consider is Power Automate Desktop but would certainly prefer a better approach.
Hi Marc, I know we’ve created them programmatically using C# previously. Here’s a snippet (it was to set up bulk delete jobs for audit, but you can apply to any entity).
Feel free to reach out and we can set up a call if you’d like to review in any more detail (no charge, just offering some help).
QueryExpression queryExpression = new QueryExpression(“audit”);
FilterExpression filterExpression = new FilterExpression(LogicalOperator.And);
FilterExpression childFilter1 = new FilterExpression(LogicalOperator.Or);
FilterExpression childFilter2 = new FilterExpression(LogicalOperator.And);
childFilter2.AddCondition(“objecttypecode”, ConditionOperator.Equal, (object) 2);
childFilter1.AddCondition(new ConditionExpression(“auditid”, ConditionOperator.In, (ICollection) stringList));
filterExpression.AddFilter(childFilter2);
filterExpression.AddFilter(childFilter1);
queryExpression.Criteria = filterExpression;
BulkDeleteRequest request = new BulkDeleteRequest()
{
QuerySet = new QueryExpression[1]{ queryExpression },
JobName = “Bulk Delete of audit records with attribute mask values relating to Specific Entity”,
SendEmailNotification = false,
ToRecipients = new Guid[0],
CCRecipients = new Guid[0],
RecurrencePattern = string.Empty,
StartDateTime = DateTime.UtcNow
};
try
{
Guid jobId = ((BulkDeleteResponse) svc.Execute((OrganizationRequest) request)).JobId;
Entity entity = svc.Retrieve(“asyncoperation”, jobId, new ColumnSet(new string[3]
{
“name”,
“statecode”,
“statuscode”
}));
tracingService.Trace(string.Format(“Job Name: {0}”, entity[“name”]));
tracingService.Trace(string.Format(“Job Id: {0}”, (object) entity.Id));
tracingService.Trace("State: " + entity.FormattedValues[“statecode”]);
tracingService.Trace("Status: " + entity.FormattedValues[“statuscode”]);
}
catch (Exception ex)
{
tracingService.Trace(ex.Message);
}
I figured out a way to handle ths using the connector to Perform Unbound Actions. The action name is bulk delete.
I have a control table in Dataverse that list the table name, days to keep and then iterate thought the table I want to perform the build delete on.
We keep this flow in our default environment with the data so it is easy to select the target environment.