Bulk-loading inactive records to CDS

By | November 6, 2019


When implementing ItAintBoring.Deployment powershell modules, I did not initially add support for the “status” and “status reason” fields. Usually, we don’t need to migrate inactive reference data, but there are always exceptions, and I just hit one the other day. Reality check.

There is an updated version of the powershell script now, and there is an updated version of the corresponding nuget package.

But there is a caveat.

In CDS, we cannot create inactive records. We have to create a records as “active” first, and, then, we can deactivate it.

Just to illustrate what happens when you try, here is a screenshot of the Flow where I am trying to create a record using one of the inactive status reasons:


The error goes like this:

7 is not a valid status code for state code LeadState.Open on lead with Id d794b380-0501-ea11-a811-000d3af46cc5.

In other words, CDS is trying to use inactive status reason with the active status, and, of course, those are incompatible.

The workaround here would be to create the record first using one of the active status reasons, and, then, to change the status/status reason.

If we get back to the bulk data load through powershell scripts above, then it would look like this:

  • Export data without status/status reason into one file
  • Export data with status/status reasons into another file
  • Import the first file
  • Import the second file


In other words, in the export script I would use these two queries(notice how there is no status/status reason in the first one, and the second one is querying all attributes):


Once I’ve run the export, here is how exported data looks like – you can see the difference:


And, then, I just need to import those files in the same order.

Here is what I had before I ran the import:


Here is what I have after:


It takes a little bit of planning to bulk-load reference data this way, but, in the end, it’s just an extra run for the script, an extra fetch xml for me, and quite a bit of time saving when automating the deployment.

Leave a Reply

Your email address will not be published. Required fields are marked *