Switch Function

24 views
Skip to first unread message

Kayin Scholtz

unread,
Sep 4, 2017, 11:02:01 AM9/4/17
to OpenFn Community
Hi All,

I'd like to perform a Javascript switch function on the data coming in from a form.

I've managed to use:
    field('Disability__c', function(state) { return ((dataValue("disability")(state)==="yes")?"true":"false")}),

To transform "yes/no" to "true/false", and to find and replace specific values with the following code:

field("Race__c",function(state){
    return dataValue("race")(state).toString().replace("african","Black")

Still, my sense is that there must be an easiest way to do this than to simply write an extended find and replace. 

Any assistance would be greatly appreciated.

Best,

Kayin

Taylor Downs

unread,
Sep 9, 2017, 6:08:17 PM9/9/17
to Kayin Scholtz, OpenFn Community
Hey Kayin,

Can you share your whole job expression? I might recommend creating a custom function (or object with props set like {"original": "new"} at the outset, and then using that function in your later field calls.

We've also been thinking about letting users define replacement tables. This sounds like the right case for it.

Taylor

--
You received this message because you are subscribed to the Google Groups "OpenFn Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openfn+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openfn/906f3fcb-5d90-4645-a783-e72fe0307383%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Taylor Downs | Founder & Core Contributor
OpenFn | Integrated Systems for Development
Reply all
Reply to author
Forward
0 new messages