JavaScript as a condition or action of Business Rule
FIXEdge allows using JavaScript as a condition or action on the Business Layer.
In order to apply the JS condition/action to the FIX message, you should use the Script element.
<Condition> <Script Language="JavaScript" FileName ="testScript.js"/> </Condition> <Action> <MoveField SourceField="32" TargetField="48" /> </Action>
In order to use the script as a condition/action, it should return the value. In JS every expression returns the value and the result of the script is a value returned by the last run expression. So the boolean value can be returned in such a way:
result = false; if( "Sender" == getStringField(49) ) { result = true; } result; //last instruction to return result value
Do not use JS elements that modify the message (for example setStringField or transform) as a condition, because it will lead to an error that interrupts the script.
JavaScript reference to BL rule
FIXEdge provides users with the ability to reference parameters defined in the Condition or Action section of the BL rule from inside the script since the FIXEdge 6.14.0 release.
An example of the BL rule:
<Condition> <Script Language="JavaScript" FileName ="testScript.js"/> <Param Name="Source">NEOVEST</Param> <Param Name="Destination">JRTEST</Param> </Script> </Condition> <Action> <MoveField SourceField="32" TargetField="48" /> </Action>
An example of a reference from inside the script:
getScriptParam ("Source")