Nested Ifs - Checking for Presence of Data

Hello.

We have been using PP classic for over 2 decades. As we migrate our forms and workflows to Connect, we are faced with some challenges as Connect is a totally different beast.

Currently, we need to check on some fields to display on a form. The logic goes as follows:

If field1 is not empty, display field1
If field1 is empty and field2 is not empty, display field2
If field1 and field2 are empty and field3 is not empty, display field3
if field1, field2 and field3 are empty, display field4

We are looking for an efficient way to write this in Connect and need assistance…

There are multiple ways of achieving this, but the following conditional script would do the trick:

["field1","field2","field3","field4"].some(function(e){
   let value = record.fields[e];
   results.html(value);
   return value;
});

The [...].some() method will stop iterating through the list of fields as soon as one of the field values is non-empty.
Attached is a basic template that demonstrates the technique.
Conditional.OL-template (7.3 KB)

I’m not claiming this is better, but just to offer an alternative:

const { field1, field2, field3, field4 } = record.fields;
results.html(field1 || field2 || field3 || field4);
2 Likes

@Sander: you can claim it… it IS much better… :stuck_out_tongue:

1 Like

This is a very good solution. Thank you @Sander and @Phil!