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

fparedesac
Participant I

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!!!

0 23 1,680
23 REPLIES 23

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!

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

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

fparedesac
Participant I

if I use the condition:

LOOKUP([_THISROW].[ID_Invoice],โ€œINVOICEโ€,โ€œID_Invoiceโ€,โ€œStatusโ€)<>โ€œvalidโ€

The Add button is always showed

fparedesac
Participant I

if I use the condition:

LOOKUP([_THISROW].[ID_Invoice],โ€œINVOICEโ€,โ€œID_Invoiceโ€,โ€œStatusโ€)<>โ€œvoidedโ€

The Add button is always showed

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

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?

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.

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.

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?

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.

3X_a_4_a46df741851fe23c210815e2a2ced2a4942b9183.png

3X_5_e_5ef61ad2fbe599cb842b5918924fcfc4800f4e3a.png

Behavior definition in INVOICE_DETAIL:
3X_3_6_36598b8c89ee68e25f8955f312b0a8bbb99a12cf.png

And the next images are about view

3X_e_6_e6375435d52500e00f2701a59f3a70326bdbe4ad.png
3X_1_5_15addfee8f39776fa7a69b6b6bf4a32f1ed68136.png

Steve
Participant V

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

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.

3X_f_0_f0d33e1a1151cb399f7eeb938b3e5994a1cb0557.png

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:

Hi Steve,
I understand your idea but I tried and failed.

Both Viewable INVOICE_DETAILs and Related INVOICE_DETAILs show.
And Add action aslo show.

There seems to be no relation between slice and virtual column.

Can you post a demo app?
Thank you!

Why donโ€™t you post what you have done? It seems like a better idea

This is my app demo.

I donโ€™t know what step I did wrong in @Steve 's tutorial

Neither can anyone else if you donโ€™t show us. Attach some screenshots from every step of the tutorial.

@Marc_Dillon
I have attached the link in #19?

Sorry, I didnโ€™t check carefully!
Add button changed. But 2 column still show


Maybe this will help.

Step #5. Set the new VCโ€™s โ€œReferenced table nameโ€ to point to the new Slice.

Thank you!
I updated but nothing changed.

lubu08
Participant I

@Steve @Marc_Dillon
Thank you!
I found the answer at this link

P/S: App demo updated

Top Labels in this Space