<!-- Copyright JS Foundation and other contributors, http://js.foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <script type="text/x-red" data-help-name="switch"> <p>Route messages based on their property values or sequence position.</p> <h3>Details</h3> <p>When a message arrives, the node will evaluate each of the defined rules and forward the message to the corresponding outputs of any matching rules.</p> <p>Optionally, the node can be set to stop evaluating rules once it finds one that matches.</p> <p>The rules can be evaluated against an individual message property, a flow or global context property or the result of a JSONata expression.</p> <h4>Rules</h4> <p>There are four types of rule:</p> <ol> <li><b>Value</b> rules are evaluated against the configured property</li> <li><b>Sequence</b> rules can be used on message sequences, such as those generated by the Split node</li> <li>A JSONata <b>Expression</b> can be provided that will be evaluated against the whole message and will match if the expression returns a true value.</li> <li>An <b>Otherwise</b> rule can be used to match if none of the preceeding rules have matched.</li> </ol> <h4>Notes</h4> <p>The <code>is true/false</code> and <code>is null</code> rules perform strict comparisons against those types. They do not convert between types.</p> <p>The <code>is empty</code> rule passes for Strings, Arrays and Buffers that have a length of 0, or Objects that have no properties. It does not pass for <code>null</code> or <code>undefined</code> values.</p> <h4>Handling message sequences</h4> <p>By default, the node does not modify the <code>msg.parts</code> property of messages that are part of a sequence.</p> <p>The <b>recreate message sequences</b> option can be enabled to generate new message sequences for each rule that matches. In this mode, the node will buffer the entire incoming sequence before sending the new sequences on. The runtime setting <code>nodeMessageBufferMaxLength</code> can be used to limit how many messages nodes will buffer.</p> </script>