Writing If-Else Within the fields portion of a JOB

Is it correct to write if-else within the fields portion of openfn? as below:

.
.
fields(

if(state.data.form_field_a == “xxxxx”){

field(“field_1__c”, dataValue(“form.value_1”)),

field(“field_2__c”, dataValue(“form.value_2”)),

field(“field_3__c”, dataValue(“form.value_3”)),

field(“field_4__c”, dataValue(“form.value_4”))

}
else if (state.data.form_field_a == “yyyyyy” || state.data.form_field_a == “zzzzz”){

field(“field_1__c”, dataValue(“form.value_5”)),

field(“field_2__c”, dataValue(“form.value_6”))

}

)
.
.

NB: Job submission target is Salesforce

There are a bunch of options here. Would && or a ternary work for you? See below:

upsert(
‘Patient__c’,
‘Patient_ID__c’,
fields(
field(‘Name__c’, dataValue(‘name’)),
field(‘b’, 2),
// Omit field if test fails
state.data.testValue > 1 && field(‘c’, dataValue(‘something’)),
// Omit field with ternary if test fails
state.data.anotherTest ? field(‘d’, 13) : ‘’,
// Ternary to change field
state.data.finalTest ? field(‘e’, 16) : ‘’,
// Ternary to change value
field(‘f’, state => {
console.log(‘this is common place to calculate a value’);
const something = state.data.thatOne;
const somethingElse = 4 * 2.42 + state.data.testValue;
if (state.data.test === ‘foo’) {
return something;
}
return somethingElse;
})
)
);

Hi, I’m a newbie learning OpenFn, so probably my question is so elemental that I couldn’t found any answer at all. My problem is related with conditionals, so I write it here.

I already successfuly sent an email (with mailgun API) when a kobo submission arrives to OpenFn endpoint.

But now I want to send it to different emails according to a field value on kobo submission. So, I began to put this on the Job’s expression:

const f = state.data.f;
console.log("form name: " + f);

But get this error: “ReferenceError [Error]: f is not defined”; the error does not exists at all when console.log("form name: " + state.data.f);

Obviously, my idea was to continue with something like
if (f==“a”) then mailAddress = “x@y.com”;
and later on to use that mailAddress inside the send() function, if possible.

Clearly, I do not understand how the whole think works here.

My solution was to use different Triggers (filtering that “f” on the submitted forms from kobo) but does not seems as an “elegant” solution, specially if we have a lot of different kobotoolbox forms.

I will appreciate any advise. Thanks in advance.
Best Regards,
Kumori