Creating a custom Status for your (custom) entity

It’s been always a mystery to me why we’re not able to change the status field on an entity. We just get to change the status reason field, but sometimes you just want some more. Microsoft knows it, cause they use multiple status fields on for instance the Lead and Opportunity entity.

Let face it: most of the time it’s just fine to have Activate and Inactive as statuses on your entity. (Now that we’re talking about statuses… Isn’t it just weird that Active has the value 0 and Inactive the value 1??!) But there are those situations that you just need more. For instance one of my customers log their medical consults in an entity. In this case it would have been great to have Active, Processed and Invoiced as statuses. And you know what: it’s possible!

Now before you get too excited about this I need to temper your enthusiasm a bit. Although it can be done, it’s unsupported customization. When you read my solution and you read this article, you’ll understand why it’s unsupported. Since it’s unsupported, I would strongly advice you to do this only for custom entities and not for oob entites. So far for the disclaimer 🙂

In order to add or change the statuses you need to change the customization xml file. Now let’s go through the steps. (I expect you to have some experience with customizing Dynamics 365 CE. If not, please contact your Microsoft partner to execute these steps.)

Create the solution and get the right file

Create a temporary solution with just what you need. In this case, just add the status and status reason fields from the entity you wish to change. Although you just want to change the status field, you’ll also need the status reason field. Later on it’ll come clear why that is needed.
Export the solution and open the zip file. Now get one file out – the customization.xml file – and store it somewhere to edit.

Edit the customization xml

Now comes the editing of the file. Please be careful here, cause you might break something here.
In the file, locate this part

<states>
  <state value="0" defaultstatus="1" invariantname="Active">
    <labels>
      <label description="Active" languagecode="1033" />
    </labels>
  </state>
  <state value="1" defaultstatus="2" invariantname="Inactive">
    <labels>
      <label description="Inactive" languagecode="1033" />
    </labels>
  </state>              
</states>

As you can see, both default statuses (Active and Inactive) are there. Notice the defaultstatus tag that is in there. This is important and indicates the default status reason for that status. Since we don’t have a status reason for it yet, we will just fill in a random number now that we’ll use later to create the status reason with.

To create the new status just copy everything between a <state> and </state> tag and change the value, defaultstatus, invariantname and desciption. It should look like this. In this example I use Invoiced with vaue 10000. I would always use a high number as you never know what Microsoft comes up with in the future.

<states>
  <state value="0" defaultstatus="1" invariantname="Active">
    <labels>
      <label description="Active" languagecode="1033" />
    </labels>
  </state>
  <state value="1" defaultstatus="2" invariantname="Inactive">
    <labels>
      <label description="Inactive" languagecode="1033" />
    </labels>
  </state>
  <state value="10000" defaultstatus="20000" invariantname="Invoiced">
    <labels>
      <label description="Invoiced" languagecode="1033" />
    </labels>
  </state>                  
</states>

Now we need to do the same for the status reason field. Please keep in mind the value for the status reason should be equal to the defaultstatus value that we’ve used before. The same goes for the state.

<statuses>
  <status value="1" state="0">
    <labels>
      <label description="Active" languagecode="1033" />
    </labels>
  </status>
  <status value="2" state="1">
    <labels>
      <label description="Inactive" languagecode="1033" />
    </labels>
  </status>                    
  <status value="20000" state="10000">
    <labels>
      <label description="Invoiced" languagecode="1033" />
    </labels>                    
  </status>
</statuses>

Import the file and you’re done! 🙂

Now that you’ve changed the cusomization xml file you should put the customization xml file back into the solution zip. Notice that it overwrites the existing customization xml file. Import the solution zip back into your environment and you should have the new status.

Things to take into consideration

Again, this customization is not supported. Always be careful with these unsupported customization and question yourself if you can’t do it any other way.

Since it’s unsupported, the user interface doesn’t take your new status into account. There is no out of the box option to set a record to your new status. You can use workflow or you’ll have to create a button on the command bar to set your status.

Last but not least: as for as I could see, when a record is in the new status, its forms are always in read-only state. The Active status is the only status where you can edit the data on the form.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.