This documentation is archived and is not being maintained.

IsValidStateTransition Message (CrmService)

Dynamics
banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Works for all deployment typesWorks online and offline

Checks to see if the state transition is valid.

The relevant classes are specified in the following table.

TypeClass
RequestIsValidStateTransition
ResponseIsValidStateTransition

Remarks

To use this message, pass an instance of the IsValidStateTransition class as the request parameter in the Execute method.

For a list of required privileges, see IsValidStateTransition Privileges.

Example

This sample shows how to validate an intended state change on an entity.

[C#]
// Set up the CRM service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0; 
token.OrganizationName = "AdventureWorksCycle";
 
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create a moniker to represent an open case.
Moniker caseMoniker = new Moniker();
caseMoniker.Name = EntityName.incident.ToString();
caseMoniker.Id = createCaseResponse.id;

// Before closing an open case, check if such a state transition is valid.
IsValidStateTransitionRequest checkState = new IsValidStateTransitionRequest();

// Set the transition request to an open case.
checkState.Entity = New Guid("9f9f6170-8db3-4657-a47c-5a636cab1bae");

// Check to see if a new state of "resolved" and a new status of "closed" are valid.
checkState.NewState = IncidentState.Resolved.ToString();
checkState.NewStatus = -1;

// Execute the request.
IsValidStateTransitionResponse checkStateResponse = (IsValidStateTransitionResponse)service.Execute(checkState);

// Handle the response.
if (checkStateResponse.IsValid)
{
   // The case can be closed.
}
else
{
   // The case cannot be closed.
}
[Visual Basic .NET]
' Set up the CRM service.
Dim token As New CrmAuthenticationToken()
' You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0
token.OrganizationName = "AdventureWorksCycle";
 
Dim service As New CrmService()
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials

' Create a moniker to represent an open case.
Dim caseMoniker As New Moniker()
caseMoniker.Name = EntityName.incident.ToString()
caseMoniker.Id = createCaseResponse.id

' Before closing an open case, we need to check if such a state transition is valid.
Dim checkState As New IsValidStateTransitionRequest()

' Set the transition request to an open case.
checkState.Entity = New Guid("9f9f6170-8db3-4657-a47c-5a636cab1bae")

' Check to see if a new state of "resolved" and a new status of "closed" are valid.
checkState.NewState = IncidentState.Resolved.ToString()
checkState.NewStatus = -1

' Execute the request.
Dim checkStateResponse As IsValidStateTransitionResponse = CType(service.Execute(checkState), IsValidStateTransitionResponse)

' Handle the response.
If checkStateResponse.IsValid Then
   ' The case can be closed
Else
   ' The case cannot be closed
End If

See Also

Reference


© 2010 Microsoft Corporation. All rights reserved.


Show: