Putting two tenary operators together in one if statement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2023 07:29 AM
I've got an if statement that includes two tenary operators, but the two teneary operators shouldn't depend on each other. The if statement is:
if (updateType == 'tech') {{
grBA.u_audit_logging_monitoring_compliance = (amaGR.u_audit_monitoring == true) ? 'compliant' : 'non_compliant';}
{grBA.u_authentication_password_compliance = (amaGR.u_password_requirements == 'Yes' && amaGR.u_access_mapped_gid == 'Yes') ? 'compliant' : 'non_compliant';}
}
}
However that I've noticed is that the first tenary operator works fine, but when it executes, it sets the value of the below tenary operator incorrect. I'm trying to combine them together so that it's like the following if statement:
if (updateType == 'tech') {
if (amaGR.u_audit_monitoring == true) {
grBA.u_audit_logging_monitoring_compliance = 'compliant';
}
else {
grBA.u_audit_logging_monitoring_compliance = 'non compliant';
}
if (amaGR.u_password_requirements == 'Yes' && amaGR.u_access_mapped_gid == 'Yes') {
grBA.u_authentication_password_compliance = 'compliant';
}
else {
grBA.u_authentication_password_compliance = 'non compliant';
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2023 01:43 PM
Hi @matthew_hughes,
Not sure this is the best use case for a ternary option. Based on some reading, it seems that ternary is best for many nested conditions for consolidation, such as this:
This nested condition is clean and concise. Counter that with just some if/else logic, like that which is presented here, and it's less visually appealing while achieving the same result. Another example document
I'm maybe not understanding the why of this approach and I apologize if I was not helpful.
-Matt