Skip to main content

DTL <if>

Evaluate a condition and perform one action if true, another if false.

Syntax

<if condition="1">
   <true>
     ...
   </true>
   <false>
     ...
   </false> 
</if>

Attributes

Attribute Description Value
condition Required. An expression that, if true, causes the contents of the <true> element to execute. If false, the contents of the <false> element are executed. The expression must use the scripting language specified by the containing <transform> element: basic or objectscript. If not specified, the default is objectscript. MVBasic is not supported. An expression that evaluates to the integer value 1 (if true) or 0 (if false).

Elements

Element Purpose
<annotation> Optional. A text string that describes the <if> element.
<true> Optional. If the condition is true, activities inside the <true> element are executed.
<false> Optional. If the condition is false, activities inside the <false> element are executed.

Description

The <if> element evaluates an expression and, depending on its value, executes one of two sets of activities (one if the expression evaluates to a true value, the other if it evaluates to a false value).

The <if> element may contain a <true> element and a <false> element which define the actions to execute if the expression evaluates to true or false, respectively.

If both <true> and <false> elements are provided, they may appear within the <if> element in any order.

If the condition is true and there is no <true> element, or if the condition is false and there is no <false> element, no activity results from the <if> element.

The following example shows an <if> element within a DTL data transformation. The <if> activity in this example has a condition that tests the value of the source attribute PID:2.4. If it is the string 'A' then the <true> statement assigns the value '001' to the attribute, in place of 'A':

<transform targetClass='EnsLib.HL7.Message'
           targetDocType='2.3.1:MDM_T02'
           sourceClass='EnsLib.HL7.Message'
           sourceDocType='2.3.1:MDM_T02'
           create='new'
           language='objectscript'>
 <assign property='target.{MSH}' value='source.{MSH}' action='set'/>
 <assign property='target.{MSH:3}' value='"SOFTMAX"' action='set'/>
 <assign property='target.{MSH:4}' value='"001"' action='set'/>
 <assign property='target.{MSH:5}' value='"STARTCOM"' action='set'/>
 <assign property='target.{MSH:6}' value='"001"' action='set'/>
 <assign property='target.{EVN}' value='source.{EVN}' action='set'/>
 <assign property='target.{EVN:1}' value='"T02"' action='set'/>
 <assign property='target.{PID}' value='source.{PID}' action='set'/>
 <if condition='source.{PID:2.4}="A"'>
   <true>
     <assign property='target.{PID:2.4}' value='"001"' action='set'/>
   </true>
 </if>
 <assign property='target.{PID:3().4}' value='"001"' action='set'/>
 <assign property='target.{PID:18.4}' value='"001"' action='set'/>
 <assign property='target.{PID:21.4}' value='"001"' action='set'/>
 <assign property='target.{TXA}' value='source.{TXA}' action='set'/>
 <assign property='target.{TXA:5.10}' value='"001"' action='set'/>
 <assign property='target.{TXA:5.15}' value='"001"' action='set'/>
 <assign property='target.{TXA:9.10}' value='"001"' action='set'/>
 <assign property='target.{TXA:9.15}' value='"001"' action='set'/>
 <assign property='target.{TXA:10.10}' value='"001"' action='set'/>
 <assign property='target.{TXA:10.15}' value='"001"' action='set'/>
 <assign property='target.{TXA:11.10}' value='"001"' action='set'/>
 <assign property='target.{TXA:11.15}' value='"001"' action='set'/>
 <assign property='target.{TXA:12.2}' value='"SOFTMAX"' action='set'/>
 <assign property='target.{TXA:22.10}' value='"001"' action='set'/>
 <assign property='target.{TXA:22.15}' value='"001"' action='set'/>
 <assign property='target.{TXA:23.10}' value='"001"' action='set'/>
 <assign property='target.{TXA:23.15}' value='"001"' action='set'/>
 <assign property='target.{OBX()}' value='source.{OBX()}' action='set'/>
</transform>
FeedbackOpens in a new tab