Autofill not filling the fields

I have 2 Tables - Orders and Customer

Order Table has fields - Customer and Customer ID

What I am trying to do is In Orders Form ( when creating or editing the order) I want to autofill the Customer ID (referring the customers table) upon the selection of the Customer . I tried the LOOKUP but its not working the way it should. Its showing me the customer (name) in the customer ID field too instead of customer ID. And when I select the customer from the drop down, the entire Customer ID field is getting disappeared from the Order Form .

This is what I have used but doesnt seem working.

LOOKUP( [_THISROW].[Customer] , Customers , Customer , Customer_ID )

Where am I going wrong ?

First: change the post to a question - since this isn’t a tip on how to do something. :wink:

Second: you’ll want to check out references:

They’ll allow you to connect things together and do what you’re wanting automagically.

Hope it helps!

I also Changed the Customer ID column type from Ref to Text. It seems to have solved a bit but not completely. On Changing the customer name, the customer name field is getting filled with customer ID Value.

1 Like

How are you getting that value?

With a reference, you should de-reference it

1 Like

Hello. I did exactly as in the article and even the video along. Its doing the right reference now but the other problem still remains… populating (changing) the Customer Name with Customer ID .

That would use a dereference expression lilke this:

[Customer ID].[Name]

replacing Name with whatever the name of the column is in the customers table that contains the customer’s name.

1 Like

Actually the dereference problem is sorted I think. Upon the customer (name) selection, the ID is getting stored in the customer ID Column so far so good. But it stores the same customer ID in the customer(name) field too. It shows the customer (name) in the dropdown but stores as ID in the field. Kindly refer the image in my previous post.

I stand by my suggestion above.

Where should I have this expression . In the customer (name) Field which is of Type Ref. This is what I have currently

In the Order Table

Oh, Customer is the Ref. I suggest you reverse them. Make Customer ID the Ref and fill in Customer with the customer’s name.

1 Like

Works .This was the first thing I did but got the list of customer IDs in dropdown instead of the name, should have made some mistake. So reversed the ref to customer name field to make the selection easy but it got worse. Anyway, it works at last. Thanks Steve.

While my problem is solved and is all fine, I am still confused as to how the dropdown automatically lists the customer names and not the other columns from the customer table like the City or others. Is this preconfigured or some intelligence applied ?

I am trying to understand this because I want to populate the dropdown values according to my wish in other views which I am working on.

1 Like

When a column is of type Ref (or List of Ref), the actual column value is the key column value of the row of the referenced table, but AppSheet displays the label column value of the row. This is built-in behavior for Ref values.

See also:

1 Like

Great Got that … So it takes the label value by default. But what if we want a field which is not Label in the drop down or in other instances when I want 2 fields together . Say , the customer and City for example to make the identification and selection of the value from the drop-down easy.

No, it uses the label value, period. There is no alternative.

Then you can’t use a Ref value.

You’d have to change the label column to one that includes the entire desired text.

1 Like

Cool… Thx Steve.

1 Like