diff --git a/ui-ngx/src/assets/help/en_US/rulenode/common_node_script_args.md b/ui-ngx/src/assets/help/en_US/rulenode/common_node_script_args.md index ef53ae37f8..296e5b735c 100644 --- a/ui-ngx/src/assets/help/en_US/rulenode/common_node_script_args.md +++ b/ui-ngx/src/assets/help/en_US/rulenode/common_node_script_args.md @@ -1,8 +1,11 @@ + +Enable 'debug mode' for your rule node to see the messages that arrive in near real-time. +See Debugging for more information. \ No newline at end of file diff --git a/ui-ngx/src/assets/help/en_US/rulenode/filter_node_script_fn.md b/ui-ngx/src/assets/help/en_US/rulenode/filter_node_script_fn.md index 3740d88c64..862590867b 100644 --- a/ui-ngx/src/assets/help/en_US/rulenode/filter_node_script_fn.md +++ b/ui-ngx/src/assets/help/en_US/rulenode/filter_node_script_fn.md @@ -5,7 +5,7 @@ *function Filter(msg, metadata, msgType): boolean* -JavaScript function evaluating **true/false** condition on incoming Message. +JavaScript function defines a boolean expression based on the incoming Message and Metadata. **Parameters:** @@ -13,19 +13,34 @@ JavaScript function evaluating **true/false** condition on incoming Message. **Returns:** -Should return `boolean` value. If `true` - send Message via **True** chain, otherwise **False** chain is used. +Must return a `boolean` value. If `true` - routes Message to subsequent rule nodes that are related via **True** link, +otherwise sends Message to rule nodes related via **False** link. +Uses 'Failure' link in case of any failures to evaluate the expression.
##### Examples -* Forward all messages with `temperature` value greater than `20` to the **True** chain and all other messages to the **False** chain: +* Forward all messages with `temperature` value greater than `20` to the **True** link and all other messages to the **False** link. + Assumes that incoming messages always contain the 'temperature' field: ```javascript return msg.temperature > 20; {:copy-code} ``` + +Example of the rule chain configuration: + +![image](${helpBaseUrl}/help/images/rulenode/examples/filter-node.png) + +* Same as above, but checks that the message has 'temperature' field to **avoid failures** on unexpected messages: + +```javascript +return typeof msg.temperature !== 'undefined' && msg.temperature > 20; +{:copy-code} +``` + * Forward all messages with type `ATTRIBUTES_UPDATED` to the **True** chain and all other messages to the **False** chain: ```javascript diff --git a/ui-ngx/src/assets/help/en_US/rulenode/generator_node_script_fn.md b/ui-ngx/src/assets/help/en_US/rulenode/generator_node_script_fn.md index b3f5bcd059..ac8b6abf56 100644 --- a/ui-ngx/src/assets/help/en_US/rulenode/generator_node_script_fn.md +++ b/ui-ngx/src/assets/help/en_US/rulenode/generator_node_script_fn.md @@ -5,7 +5,7 @@ *function Generate(prevMsg, prevMetadata, prevMsgType): {msg: object, metadata: object, msgType: string}* -JavaScript function generating new message using previous Message payload, Metadata and Message type as input arguments. +JavaScript function generating new Message using previous Message payload, Metadata and Message type as input arguments. **Parameters:** @@ -24,13 +24,13 @@ Should return the object with the following structure: ```javascript { - msg?: {[key: string]: any}, - metadata?: {[key: string]: string}, - msgType?: string + msg: {[key: string]: any}, + metadata: {[key: string]: string}, + msgType: string } ``` -All fields in resulting object are optional and will be taken from previously generated Message if not specified. +All fields in resulting object are mandatory.
@@ -39,14 +39,11 @@ All fields in resulting object are optional and will be taken from previously ge * Generate message of type `POST_TELEMETRY_REQUEST` with random `temperature` value from `18` to `32`: ```javascript -var temperature = 18 + Math.random() * 14; +var temperature = 18 + Math.random() * (32 - 18); // Round to at most 2 decimal places (optional) temperature = Math.round( temperature * 100 ) / 100; var msg = { temperature: temperature }; -var metadata = {}; -var msgType = "POST_TELEMETRY_REQUEST"; - -return { msg: msg, metadata: metadata, msgType: msgType }; +return { msg: msg, metadata: {}, msgType: "POST_TELEMETRY_REQUEST" }; {:copy-code} ``` @@ -62,9 +59,7 @@ and metadata with field data having value 40 ```javascript var msg = { temp: 42, humidity: 77 }; var metadata = { data: 40 }; -var msgType = "POST_TELEMETRY_REQUEST"; - -return { msg: msg, metadata: metadata, msgType: msgType }; +return { msg: msg, metadata: metadata, msgType: "POST_TELEMETRY_REQUEST" }; {:copy-code} ``` @@ -108,9 +103,8 @@ if (isDecrement === 'true') { var msg = { temperature: temperature }; var metadata = { isDecrement: isDecrement }; -var msgType = "POST_TELEMETRY_REQUEST"; -return { msg: msg, metadata: metadata, msgType: msgType }; +return { msg: msg, metadata: metadata, msgType: "POST_TELEMETRY_REQUEST" }; {:copy-code} ``` diff --git a/ui-ngx/src/assets/help/en_US/rulenode/switch_node_script_fn.md b/ui-ngx/src/assets/help/en_US/rulenode/switch_node_script_fn.md index de08fb9020..a31eae72cf 100644 --- a/ui-ngx/src/assets/help/en_US/rulenode/switch_node_script_fn.md +++ b/ui-ngx/src/assets/help/en_US/rulenode/switch_node_script_fn.md @@ -5,7 +5,7 @@ *function Switch(msg, metadata, msgType): string[]* -JavaScript function computing **an array of next Relation names** for incoming Message. +JavaScript function computing **an array of Link names** to forward the incoming Message. **Parameters:** @@ -13,8 +13,9 @@ JavaScript function computing **an array of next Relation names** for incoming M **Returns:** -Should return an array of `string` values presenting **next Relation names** where Message should be routed.
-If returned array is empty - message will not be routed to any Node and discarded. +Should return an array of `string` values presenting **link names** that the Rule Engine should use to further route the incoming Message.
+If the result is an empty array - message will not be routed to any Node and will be immediately +acknowledged.
@@ -24,7 +25,7 @@ If returned array is empty - message will not be routed to any Node and discarde
  • Forward all messages with temperature value greater than 30 to the 'High temperature' chain,
    with temperature value lower than 20 to the 'Low temperature' chain and all other messages
    -to the 'Normal temperature' chain: +to the 'Other' chain:
  • @@ -34,11 +35,15 @@ if (msg.temperature > 30) { } else if (msg.temperature < 20) { return ['Low temperature']; } else { - return ['Normal temperature']; + return ['Other']; } {:copy-code} ``` +Example of the rule chain configuration: + +![image](${helpBaseUrl}/help/images/rulenode/examples/switch-node.png) +