Example for StateTransition Activity

In the following example, the activity tries to create a new conversation assuming that the message was never received before.

It builds keys as "Message" + "InternalID + PublishDate" – if this key is already found in the system, then the activity will set ‘couldMoveToNew’ as ‘false’. The couldMoveToNew can then be used to handle can where a duplicate message is received.

<Activity Name="MessageReceived">
  <Start/>
  <Action>StateTransition</Action>
  <Description lang="en">Set state to new message received</Description>
  <Parameter direction="in" type="string" eval="constant"   name="eventState">NEWMESSAGE</Parameter>
  <Parameter direction="in" name="InDocument" type="document"   eval="variable">inDoc</Parameter>
  <Parameter direction="in" name="ConversationAction" eval="constant"   type="string">new</Parameter>
  <Parameter direction="in" name="CheckTransition" eval="constant"   type="string">true</Parameter>
  <Parameter direction="in" name="MoveTo" eval="constant"   type="string">NEW</Parameter>
  <!-- Key is made up of "Message" + "InternalID + PublishDate" -->
  <Parameter direction="in" name="Key1" eval="constant"   type="string">Message</Parameter>
  <Parameter direction="in" name="Key2" eval="xpath" type="string"   source="/Message/@externalControlNumber">inDoc</Parameter>
  <Parameter direction="in" name="Key3" eval="xpath" type="string"   source="//CatalogReference[@type='Catalog']/RevisionID/DBID/text()">inDoc
  </Parameter>
  <Parameter direction="in" name="Key3" eval="xpath" type="string"   source="//CatalogReference[@type='MasterCatalog']/RevisionID/DBID/text()">  inDoc</Parameter>
  <Parameter direction="out" eval="variable" type="document"   name="OutDocument">workDoc</Parameter>
  <Parameter direction="out" name="ConversationState" eval="variable"   type="string">newState</Parameter>
  <Parameter direction="out" name="CouldMove" eval="variable"   type="boolean">couldMoveToNew</Parameter>
</Activity>

When defining work item chains in generic workflows, you can use the statetransition activity to set up a "mini state machine" to control how many times the workflow loops through that work item.

Setting up Mini State Machine