convert user capture
Hi everyone, I have a simple for some but not for me π issue. When the user answers yes or no to a capture, I need to convert it to true or false when I send my api call to create the record. I would like to do this so it's reusable for several captures in the flow. I tried functions but did not work as expected. Any other suggestions? Thanks in advance.
2 Replies
Youβve got two easy, reusable ways to flip a βyes / noβ capture into a true / false value before you hit your API step.
ββββββββββββββββββββββββ
1) Inline conversion right inside the API body
ββββββββββββββββββββββββ The JSON Body editor lets you use little JS expressions inside {{= β¦ }}.
Example (assume the capture is stored in {yes_no}): When the request is sent: β’ if the user said βyesβ β
β’ anything else (no, nope, etc.) β
ββββββββββββββββββββββββ Create a Function step with one INPUT variable (e.g. answer) and one OUTPUT variable (e.g. bool_answer).
Paste this code: β’ Drop this Function anywhere you need the conversion.
β’ Pass the capture into
ββββββββββββββββββββββββ The JSON Body editor lets you use little JS expressions inside {{= β¦ }}.
Example (assume the capture is stored in {yes_no}): When the request is sent: β’ if the user said βyesβ β
"agreed": true
β’ anything else (no, nope, etc.) β
"agreed": false
Nothing else to maintain, and you can reuse that one-liner anywhere you reference the variable.
ββββββββββββββββββββββββ
2) A reusable Function block (if you prefer a dedicated step)ββββββββββββββββββββββββ Create a Function step with one INPUT variable (e.g. answer) and one OUTPUT variable (e.g. bool_answer).
Paste this code: β’ Drop this Function anywhere you need the conversion.
β’ Pass the capture into
answer
, the step spits out bool_answer
(true/false) ready for your API body.
Either route keeps your flow clean and 100 % reusable. Pick the one that fits your style!this is great. Do you know if calling this function multiple times (5x +) will increase the number of credits consumed? The credits VF use it's crazy. a conversation in my flow ranges from 40 to 60. I would need hundreds of thousands to roll it out to production. I appreciate the help.