Enable or disable the Add button in a master-detail form

Hi everyone, this is my first APP using Appsheet, so I appreciate your help with a problem I have.

Part of my App is an invoice with its detail, I have two tables, one of Invoice and the other Invoice_Detail. The two tables are linked to the ID_Invoice column. The invoice can have two states (valid, voided), I control the change of state with an Action and it works correctly.

In the UX section when I save an invoice, it takes me to the detail view and shows me at the bottom an inline form of the invoice detail with the buttons to view and to add new lines.

What I need is that if the status of an invoice is Voided, that the add line button does not show. To do that, in the Add action of the Invoice_Detail I wrote this condition:

LOOKUP([ID_Invoice],“INVOICE”,“ID_Invoice”,“Status”)=“valid”

The problem is that in any state of the invoice it hides the Add button.

Thanks your help!!!

You’d likely want:
[_THISROW].[ID_Invoice] for your first parameter
(see #troubleshooting in LOOKUP() | AppSheet Help Center to understand why :))

Let me know it that works for you!

1 Like

Hi Patrick, thanks for your answer, I already tried it like this but it does not work, the button is still not showing for any status of the invoice

1 Like

Thanks for checking, I would be curious as to what would happen if you use <> “voided”, would like to isolate the issue to whether or not it’s the lookup or the equality check that’s problematic

1 Like

if I use the condition:

LOOKUP([_THISROW].[ID_Invoice],“INVOICE”,“ID_Invoice”,“Status”)<>“valid”

The Add button is always showed

1 Like

if I use the condition:

LOOKUP([_THISROW].[ID_Invoice],“INVOICE”,“ID_Invoice”,“Status”)<>“voided”

The Add button is always showed

1 Like

Hm then I’m not so sure. One thing to try is to create a virtual column on invoice_detail that evalulates to LOOKUP([_THISROW].[ID_Invoice],“INVOICE”,“ID_Invoice”,“Status”) and see what that output looks like and make sure it matches your expectations

1 Like

I have one virtual column to evaluate exactly your idea, and the values showed are OK, the data is correct in Invoice_Detail vs Invoice Status.

Is there any way to debug in appsheet? to know the data against which App be comparing the condition?

1 Like

IF in your Invoice_Detail table, the column ID_Invoice is a Ref column, i.e. a pointer back to the Parent Invoice row, (by the way, if it’s not…it should be) then you can take advantage of “dot” notation to retrieve the status and simplify the expression like this:

[ID_Invoice].[Status] <> "valid"

It seems you have ID_Invoice as a column in both tables? LOOKUP() is expanded into an ANY(SELECT()) combination of functions. I suspect that resulting expression is then experiencing some ambiguity with same column names and not finding the correct value.

The expression above is simpler anyway. :slight_smile:

As a side note, I found a few places where when column names are the same across related tables you run into these ambiguity problems - templates are another one of those areas. I would recommend refraining from using the same column name in these cases.

1 Like

Hello John, thanks your time.

I try your expression and other variations but the behavior is the same, the Add button does not show.

[ID_Invoice].[Status] <> “valid”
[_THISROW].[ID_Invoice].[Status] <> “valid”

If change condition the button is always showed.

[ID_Invoice].[Status] = “valid”

I checked the test expresion button with data population and expression results is correct, “Voided” status is FALSE and “Valid” Satus is TRUE, but the button does not show.

Any other idea?

1 Like

Can you show us the column definition of ID_Invoice in your Invoice_Detail table? I think there might be something not set correctly there.

1 Like

https://community.appsheet.com/search?q=@steve%20quirk

image

image

Behavior definition in INVOICE_DETAIL:
image

And the next images are about view

image
image

Hi Steve, thanks for your time.

I tested Legacy and Consistent option in this case and the behavior is the same.

The data in tables (INVOICE, INVOICE_DETAIL) are very simple, only 2 rows each one, and no BLANK data exist.

Following your suggestion in one of your posts I changed the expression using IN instead of =. I checked the Expression Test window and it evaluates the condition correctly, but in the App it doesn’t.

image

1 Like

This:

[_THISROW].[ID_Invoice].[STATUS]

should be:

[ID_Invoice].[STATUS]

Wait, wait, wait…

The Add action is not presented in a row context, so you cannot reference columns of the current row.

To do what you want to do, you aren’t going to reconfigure the Add action at all. Instead, you need to do the following:

  1. Create a slice of the INVOICE_DETAIL table with no Row filter condition expression, and with Update mode set to Read-Only.

  2. Add a virtual column to the INVOICES table called Viewable INVOICE_DETAILs and an App formula expression of:

    [Related INVOICE_DETAILs]
    
  3. For the Viewable INVOICE_DETAILs column, set Show? to the expression:

    [INVOICE_ID].[Status] = "voided"
    
  4. For the Related INVOICE_DETAILs column, set Show? to the expression:

    [INVOICE_ID].[Status] = "valid"
    

See also: