Section I – SCXML > SCXML > Modularity         Bottom of Page
Genesys 8.1
SCXML Technical Reference
< Ownership            Session Scope >

Modularity

There are several ways to support modularity and reusability with SCXML:

The following is an example of a targetless transition style subroutine. The input event is "inputsub1" and the output event is "outputsub1". Several steps are chained together to provide a moderately complex subroutine. This mechanism should only be used with events generated by the steps of the subroutine; otherwise asynchronous events generated by actions could result in steps not being executed properly.

	<state id="ParentState">
		<transition event="inputsub1">
			<script>
				local.eMailID = _genesys.getValue(_event.data.i_ixn,"'InteractionId'");
			</script>
			<log expr="_event.data.i_message" level="3"/>
			<session:fetch requestid="_data.reqid" srcexpr="'someURL/AUDIT_PROC'" timeout="10">
				<param name="audit_info" expr="_event.data.i_message"/>
				<param name="message_id" expr="local.eMailID"/>
			</session:fetch>
		</transition>

		<!-- This an example of branching within a targetless transition subroutine -->
		<!-- It examines the event generated by the session:fetch action -->
		<!-- If value1 is less than or equal to 10 go to step 2. -->
		<transition event="session.fetch.done" cond="(_event.requestid == _data.reqid) &amp;&amp; (_event.data.content.value1 &lt;= "10")">
			<raise event="sub1step2">
				< param name ="s1v1" expr ="_event.data.value1"/>
			</raise>
		</transition>

		<!-- If value1 is greater than to 10 go to step 3. -->
		<transition event="session.fetch.done" cond="(_event.requestid == _data.reqid) &amp;&amp; (_event.data.content.value1 &gt; 10)">
			<raise event="sub1step3">
				< param name ="s1v1" expr ="_event.data.value1"/>
			</raise >
		</transition>

		<!-- This is the processing for step 2 of the subroutine sub1 -->
		<transition event="sub1step2" >
			<script>
				<! — do some extra processing -->
			</script>
			<!-- Return to the involving state -->
			<raise event="outputsub1">
				<param name ="sub1op1" expr ="variablex"/>
				<param name ="rc" expr ="success"/>
			</raise>
		</transition>

		<!-- This is the processing for step 3 of the subroutine sub1 -->
		<transition event="sub1step3" >
			<script>
				<!-- do some extra processing -->
			</script>
			<if conn="variable &gt;=100">
				<!-- Return to the involving state -->
				<raise event="outputsub1">
					<param name ="sub1op1" expr ="variablex"/>
					<param name ="rc" expr ="success"/>
				</raise>
			</else >
				<!-- go to step 4 -->
				<raise event="sub1step4">
					<param name ="sub1op1" expr ="variablex"/>
					<param name ="sub1op1" expr ="variabley"/>
				</raise>
			</if>	
		</transition>

		<!-- This is the processing for step 4 of the subroutine sub1 -->
		<transition event="sub1step4" >
			<script>
				<!-- do some extra processing -->
			</script>
			<!-- Return to the involving state -->
			<raise event="outputsub1">
				<param name ="sub1op1" expr ="variablex"/>
				<param name ="rc" expr ="success"/>
			</raise>
		</transition>

		<!-- General error processing for this sub1 -->
		<!-- Note that this will treat all error events as a failure of this subroutine -->
		<!-- Care should be taken to ensure that this is only called as part of the subroutine -->
		<transition event="error.*" cond="_event.requestid == _data.reqid">
			<log expr="had an error with the fetch" level="3"/>
			<raise event="outputsub1">
				< param name ="rc" expr ="fetchfailed"/>
			</raise >
		</transition>


		<!-- This is the state that invokes the subroutine -->
		<state id="stepwhichinvokessub1">
			<onentry>
				<raise name ="inputsub1">
					<param name ="i_message" expr ="'here is the message'">
					<param name ="i_ixn" expr ="_data.interaction"">
				</raise">
			</onentry>
			<transition event="outputsub1">
				<if cond = (_event.data.rc == "success")>
					<!-- do the processing to continue based on sub1 completing -->
				</else >
 					<!-- do the processing to continue based on sub1 failing -->
				</if>
			</transition>
		</state>
	</state>



Section I – SCXML > SCXML > Modularity         Top of Page
Genesys 8.1
SCXML Technical Reference
< Ownership            Session Scope >