Understanding StateCode, StatusCode, Status and Status Reason in Dynamics 365

1 Comment

In Dynamics 365, entities contain the fields StateCode and StatusCode. If we create a new entity, we can see the statecode (display name Status) and statuscode (display name Status Reason) fields are automatically created:

We can also see the types of these fields are Status and Status Reason respectively.

Let’s look at the Status field. We can see it is of type Status, but we do not see any values associated with it:

The Status Reason is of type Status Reason and has one value called Active:

We can rename and delete Active if we want to:

We can also add our own values:

If we look in Advanced Find at our new entity and filter on Status, we can see there are 2 options – Active and Inactive:

With Status Reason, we get Active, Inactive and In Progress (the new one we added):

The Status Reason is a special field, in that in the toolbar we see Edit Status Reason Transitions:

You can read more about those on my post here.

Let’s look at other entities in the system. First, Accounts. This has 2 states, Active and Inactive:

And 2 status reasons:

For Opportunities, status is Won, Lost, Open:

And Status Reason has several options (Accepted, Canceled etc):

The Opportunity Status contains the data type:

And Status Reasons we can create/edit/delete:

Note if we look for statecode or statuscode in global option sets, we will not see it:

To get these option set labels, we can use the Web API and access EntityDefinitions.

For state:

https://yourorg.api.crm.dynamics.com/api/data/v9.1/EntityDefinitions(LogicalName=’opportunity’)/Attributes/Microsoft.Dynamics.CRM.StateAttributeMetadata?$expand=OptionSet

Here we can see Won, Lost, Open states:

For status:

https://yourorg.api.crm.dynamics.com/api/data/v9.1/EntityDefinitions(LogicalName=’opportunity’)/Attributes/Microsoft.Dynamics.CRM.StatusAttributeMetadata?$expand=OptionSet

Here we can see the Open for Bidding label in the query:

 

THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

One Response to Understanding StateCode, StatusCode, Status and Status Reason in Dynamics 365

  1. Do you know how to get the Status as input in a custom workflow activity? I tried to use OptionSetValue and it didn’t work

Leave a Reply

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