IF and SELECT in templates

Hi, how can I work with different tables in a template?

Example I have thes three tables, one with customers, other with relations between Customers and other with Sales:

Customers
document(pk)
name
lastname
dob
age

Relations
id_relation(pk)
document1(pk_Customers)
document2(pk_Customers)
tutor(Y/N)

Sales
id_sales(pk)
customer(pk_Customers)

Template grow from Sales table.

In the template i need to indicate “YES” if the person is under 18 or “NO” if the person is 18 years or older. And if customer is under 18 display the data of the Customer who have tutor attribute on YES(there will be only one with this condition).

I tryed with: <<IF:SELECT(Customers[age],[document]=[customer])<18>>“YES”<<endif>> and didn´t work.

Alone SELECT(Customers[age],[document]=[customer]) display the age data correctly.

For the second step, if the result of condition was “YES” show the Customers data who is tutor, i´m lost.

Thaks comunity!

The IF condition is not in proper syntax. You need to wrap the SELECT() with an ANY() function like so:

<<IF:ANY(SELECT(Customers[age],[document]=[customer]))<18>>“YES”<<endif>>

EDITED: Corrected so that endif would show. Thanks @Steve !!


I would recommend reviewing these articles for more details about working in tempaltes.

And this Support Search will provide several others that might be of interest:

https://www.appsheet.com/Support?q=templates&hPP=10&idx=help&p=0&is_v=1

2 Likes

Hi, it was easier, i wasn`t familiar with “dereference”. Solution was:
On sales table:
<<IF: [customer].[age]<18>>YES<>

But, ¿how many dereferences can be nested?

Still working on the second step.

Thanks!

2 Likes

Nested dereferences were recently introduced. What limit is there? I’m not certain and don’t recall it documented.

If by “nested” you mean “chained” (e.g., [a].[b].[c]), I believe three is new limit, but it should be easy enough to test longer chains and find out.

2 Likes