Microsoft Dynamics CRM 2013 Status Reason Transitions – Part 3

Colin Maitland, 17 June 2014

In my previous blog I have outlined the differences between using Update or Set State when using Business Rules, Workflow Processes and Plugin Processes to change the Status and/or Status Reason of records for an entity where Status Transitions is enabled. In this blog I will briefly describe the sample code provided by Microsoft that demonstrates how to obtain a list of valid Status Reason Transitions for a specified Entity and Status Reason.

The following is a list of the actions of methods that may be used to change the Status and/or Status Reason of records:

METHOD

STATUS

STATUS REASON

COMMENTS

Workflow Process

Set State

Set State

-

Business Rule

-

Set Field Value

As long as the new Status Reason value is for the current Status.

SDK Method

(e.g. Plugin Process)

SetStateRequest

Update

SetStateRequest

-

 

In my previous blog I described the fact that using a Business Rule Set Field Value action or the SDK Organisation Service Update method does not result in enabled Status Reason Transitions being enforced. I also described that using the Set Status action or the SetStateRequest does result in enabled Status Reason Transitions being enforced; i.e. when the Enable State Transitions property of the Entity is enabled and the new Status Reason is an invalid Status Reason Transition, from the current Status Reason for that eEntity, then an error is thrown.

Microsoft have provided sample SDK code that may be used to obtain and return a list of valid Status Reason values for a specific Entity and Status Reason, e.g. GetValidStatusOptions(String entityLogicalName, int currentStatusValue). For a specific Entity and Status Value this function retrieves and returns a list of valid Status and Status Reasons. This list may then be used to check against prior to attempting to change the current Status Reason of the record to a new Status Reason.

http://msdn.microsoft.com/en-us/library/dn689060.aspx 

The sample GetValidStatusOptions(…) method performs the following actions: 

1.  Initializes a StatusOption List.

2.  Retrieves the entity metadata and option set values metadata for the State (Status) and Status (Status Reason) attributes for a specified entity.

3.  Checks the EnforceStateTransitions property of the entity.

4.  If the EnforceStateTransitions property is True, populates the StatusOption list with a list of the valid State (Status) and Status (Status Reason) values for the specified Entity and Status Reason.

5.  If the EnforceStateTransitions property is False, populates the StatusOption list with a list of all the State (Status) and Status (Status Reason) values for the specified Entity, excluding the specified Status Reason (i.e. the current Status Reason).

6.  Returns the StatusOption list.

7.  The returned StatusOption list contains the following properties for each returned Status Reason:

  •  StateLabel
  •  StateValue
  •  StatusLabel
  •  StatusValue

In conclusion, it is up to the developer to check whether Status Reason Transitions is enabled for a specified Entity, and if so if a proposed new Status Reason is a valid Status Reason Transition, when using the Update or SetStateRequest methods to change the Status and/or Status Reason of records.