Bulk delete in imported records in CRM Dynamics RRS feed

  • Question

  • Hi,

    I imported records from csv into CRM entity using import data map via SDK.

    Now i want to delete imported records via sdk.In Map entity interface we have bulk delete option that will delete related records from the corresponding entity but through programatically how can i to do?

    Can any one please send sample code for these?


    Friday, January 23, 2015 9:50 PM

All replies

  • Hi,

    The import by data map use the importsequencenumber attribut on records created by the import.

                //Retrieve ImportId From ImportFileId
                QueryExpression _query = new QueryExpression("importfile")
                    ColumnSet = new ColumnSet("importid", "targetentityname"),
                    Criteria = new FilterExpression(LogicalOperator.And)
                        Conditions =
                            new ConditionExpression("name", ConditionOperator.Equal, "Sample Data Lead"),
                EntityCollection _importFilesCol = _serviceProxy.RetrieveMultiple(_query);
                Entity _importFile = _importFilesCol.Entities[0];
                Guid _importId = _importFile.GetAttributeValue<EntityReference>("importid").Id;
                string _targetEntityName = _importFile.GetAttributeValue<String>("targetentityname");  
                //Retrieve ImportSequenceNumber From ImportId
                Entity _import = _serviceProxy.Retrieve("import", _importId, new ColumnSet("sequence"));
                int _sequence = (int)_import["sequence"];
                //Job Request
                QueryExpression[] array = new QueryExpression[1];
                QueryExpression queryExpression = new QueryExpression();
                queryExpression.EntityName = _targetEntityName;
                queryExpression.Criteria.AddCondition("importsequencenumber", ConditionOperator.Equal, _sequence);
                array[0] = queryExpression;
                BulkDeleteRequest _bulkDeleteRequest = new BulkDeleteRequest()
                    QuerySet = array,
                    StartDateTime = DateTime.Now,
                    RecurrencePattern = String.Empty,
                    SendEmailNotification = false,
                    ToRecipients = new Guid[]{},
                    CCRecipients = new Guid[] { },
                    JobName = "Bulk Deletion",


    Blog : Dynamics CRM pour les francophones/for French speakers

    Monday, February 2, 2015 5:27 PM