This flow allows you to create a form complement with a dynamic selection list for all channels
About Function Node "Set Initial Params"
In this node the necessary objects will be created:
* msg.count => Counter required for enumerating the dynamic list
* msg.dynamicCallbackLabel => Object that will store the "callback_label" for asynchronous channels
* msg.dynamicSelectOptions => Object that will store the options for synchronous channels
About Function Node "Data Mockup - Users List"
Here is where the msg.data object is set, which gives us a fake endpoint response.
About Loop Node "Users Loop"
This node iterates the msg.data object that contains the data mockup.
About Function Node "Build The List"
* The variable "lineBreak" contains the line break for the asynchronous channels options.
* The "getNumberEmoji" function receives a numeric value and returns a numeric emoji.
* The counter is incremented.
* The values are stored dynamically in the objects "msg.dynamicCallbackLabel" and "msg.dynamicSelectOptions".
About Form Node
This node is used to generate the basic structure of a form within the "complements" object.
About Function Node "Set Form Options"
This node replaces the static properties "callback_label" and "options" with the dynamic
objects previously created in the node "Build The List".
How to test this flow?
You need to execute the Inject Node and then you can see the result in the "debug" console.
How to use this flow?
* The setting of the function node "Set Initial Params" must not be changed.
* The function node "Data mockup - User list" must be replaced by the data obtained from a Request (using http request node).
* The data obtained by the http request node will be in the "payload" object.
* Important: This data must be transferred to another object (in the example: msg.data), since this “payload” object will be replaced in each iteration of the Loop node.
* Within the "Build The List" node, the option will be stored dynamically in each iteration of the loop. (in the example: msg.payload.name)
* This will create the objects that will contain the selection lists (in the example: msg.dynamicCallbackLabel and msg.dynamicSelectOptions).
* Finally these objects will be usted to replace the parameters of the form, as follows:
- msg.payload.complements.param.callback_label = msg.dynamicCallbackLabel;
- msg.payload.complements.param.options = msg.dynamicSelectOptions;
Download the flow by clicking on this link.