Validate Record state using IsValidStateTransitionRequest in Dynamics CRM

By | April 28, 2016

Introduction:

Suppose we are going to change the state of an opportunity record programmatically by using WinOpportunityRequest request, before we make change to the state of the record it is quite important to check, the transition which we are going to execute is valid or not.

For example suppose we are going to change the state of opportunity record as won using WinOpportunityRequest request. In this scenario it is important to check whether this opportunity is in the open state or not, because only the opportunity having state as open can be changed as won.

On the other hand, suppose that the selected opportunity is already in won or lost state and we are going to change the state of the same opportunity as won then we get the following error.

The opportunity is already closed.

To overcome from the above error we can use “IsValidStateTransitionRequest”.

IsValidStateTransitionRequest request validates the transition which we are going to execute and in response returns isValid as true/false.

IsValidStateTransitionRequest request takes the following parameters as input.

  • Entity: This is an entity reference of the entity record, whose state we are going to change.
  • NewState: This parameter takes the value of the entity state which we are going to set, in the string format as shown in below sample code.
  • NewStatus: This parameter take the value of the entity status which we are going to set, in the integer format as shown in the below sample code.

Below is the sample code to execute “IsValidStateTransitionRequest” request.

Conclusion:

This will gives you the extra validation before execute the state change request.

Now Clone your Dynamics CRM records in just 1 click with Click2Clone.

Leave a Reply