<?xml version="1.0" encoding="utf-8"?>
<ManualTopic ID="/baanerp/da/onlinemanual/000304" xml:lang="en">
	<Header>
		<Title xmlns:HTML="http://www.w3.org/TR/REC-html40">Transformation script</Title>
		<Keyword ContextSensitive="No"><Level1>Triggering</Level1>
		</Keyword>
		<Keyword ContextSensitive="No"><Level1>i-Flow</Level1>
		</Keyword>
		<Keyword ContextSensitive="No"><Level1>Transformation Script</Level1>
		</Keyword>
	</Header>
	<AimSection><Paragraph class="Default">Transformation scripts are used to change the contents or the structure of the event before writing it to the XML file. In some cases, events may have to be transformed to meet the receiver's need.</Paragraph>
	</AimSection>
	<GeneralSection><Paragraph class="Default">You can for example remove attributes that are used to check a condition but should not be included in the final output. Or you can rename standard events ('create', 'change' or 'delete') to a specific event (such as 'orderedQuantityIncreased'). If required, you can even build a completely new XML structure based on the data from the event.</Paragraph>
		<Paragraph class="Default">In the transformation script, use the functions from the datrgevent library to read data from the event.</Paragraph>
		<ProcedureList><ListIntro>To create a transformation script:</ListIntro>
			<ListItem>Run the <GUIRef href="" role="manual">Transform. Script...</GUIRef> command in the <Link href="/baanerp/da/trg/datrg1225m000" role="session">Configure XML File Action (datrg1225m000)</Link> session. The text editor is started.</ListItem>
			<ListItem>Enter the Baan C code for the script.</ListItem>
		</ProcedureList>
	</GeneralSection>
	<GeneralSection><SectionTitle>TEMPLATE</SectionTitle>
		<Paragraph class="Default">Use the following code as a template for each transformation script:</Paragraph>
		<CodeBlock space-and-orientation="indented-estimated">function extern long transform.event(ref long io.event)
| IMPORTANT: do not change the interface (function name, parameter, 
| and return value)
{
DLLUSAGE
Desc            This function transforms a trigger event.
Input           io.event: event
Output          return value: 0 (OK) or &lt; 0 (an error value)
                io.event: transformed event
Precondition:   i.event contains an event that is formatted according 
                to library datrgevent and must be read using that 
                library.
Postcondition:  o.event is filled and contains an XML structure that    
                either is or is not according to library datrgevent.
ENDDLLUSAGE


        | &lt; Add implementation here &gt; |


        return(0) | OK
}

</CodeBlock>
	</GeneralSection>
	<GeneralSection><SectionTitle>EXAMPLE</SectionTitle>
		<Paragraph class="Default">See the code below for an example of a transformation script:</Paragraph>
		<CodeBlock space-and-orientation="indented-estimated">| The following transformation changes the standard events 'create',
| 'change' and 'delete to a specific event 'takeAction'. Additionally,
| it removes the 'old values', and in case of 'delete' it moves the 
| contents to the (new) values.

#define ERROR_IF(condition, return.value)
^  if condition then
^       return(return.value)
^  endif

string  event.type(LEN_TYPE)    | event type from event
long    retl                    | return value to be checked

retl = datrgevent.get.event.type(io.event, event.type)
ERROR_IF(retl &lt;&gt; 0, -2)
on case event.type
case "delete":
        retl = move.old.values.to.new.values(io.event)
        ERROR_IF(retl &lt;&gt; 0, -3)
        break
case "change":
        | delete old values
        retl = remove.old.values(io.event)
        ERROR_IF(retl &lt;&gt; 0, -4)
        break
default:
        | no action for "create" except setting event type
endcase
retl = datrgevent.set.event.type(io.event, "takeAction")
ERROR_IF(retl &lt;&gt; 0, -5)



</CodeBlock>
		<Note><SectionTitle>
                                 Note
                              </SectionTitle>
			<Paragraph class="Default">Details on the implementation of the move/remove functions are not included in this example.</Paragraph>
		</Note>
	</GeneralSection>
</ManualTopic>
