Page 1 of 1

lookup replaces field lookup (v2023)

Posted: Sun Feb 25, 2024 4:21 am
by crash

Using ASPNM23
I'm using the standard code

public void Lookup_Selecting(DbField fld, ref string filter) {
    if (fld.Name == "MyLookupField") {
        fld.Lookup.UserSelect = "SELECT Field1 AS lf, Field2 AS df, Field3 AS df2, '' AS df3, '' AS df4 FROM Table1"; // Modify SELECT
        fld.Lookup.UserOrderBy = "Field2 ASC"; // Modify ORDER BY
    }
}

I'm trying to display additional fields in the lookup but save only the first two field in the table, but all four fields in my lookup get captured and overrides the field lookup,
How do I save only the first two fields even if lookup displays four fields.

Thanks


Re: lookup replaces field lookup

Posted: Sun Feb 25, 2024 7:18 am
by MichaelG

Lookup should save the link field (lf) to the database only.


Re: lookup replaces field lookup

Posted: Sun Feb 25, 2024 7:55 pm
by crash

Thanks I've manged to get it to show only lf... when i save it shows in the view page... but now when I go back to edit page the record is empty and have to enter again.
both fiels are VarChar..


Re: lookup replaces field lookup

Posted: Mon Feb 26, 2024 6:27 am
by MichaelG

If you mean you want to show different value for lookup in view page, use the Row_Rendered server event.


Re: lookup replaces field lookup (v2023)

Posted: Tue Feb 27, 2024 4:24 am
by crash

no I mean that when you save the field the record shows in view... but when you then go back to edit the record disappears from the field, then have to re-enter the records. and then save again


Re: lookup replaces field lookup (v2023)

Posted: Tue Feb 27, 2024 7:59 am
by MichaelG

You should simply:


Re: lookup replaces field lookup (v2023)

Posted: Wed Feb 28, 2024 6:31 am
by crash

I have checked the fields match the sequence of the fields in the lookup code match the fields in the aspnm field lookup table, i tried removing the fields, tried changing the link field, no matter what I do when i go back to the edit after a successful save, the records do not show and I have to re-enter.
Fields that do not use the code works and shows the old record.


Re: lookup replaces field lookup (v2023)

Posted: Wed Feb 28, 2024 8:20 am
by MichaelG

You do not need the Lookup_Selecting codes. You should simply set up your lookup settings for use in the add/edit page and use the Row_Rendered server event to change the display value for the list/view page.


Re: lookup replaces field lookup (v2023)

Posted: Tue Mar 05, 2024 5:59 am
by crash

Row rendered seems to only modify css...


Re: lookup replaces field lookup (v2023)

Posted: Tue Mar 05, 2024 7:15 am
by MichaelG

You can modify the field view value by:

Field.ViewValue = "<new value>";

Re: lookup replaces field lookup (v2023)

Posted: Tue Mar 05, 2024 8:58 am
by crash

Thanks but then there will still be a value.. I just want to hide the last two display fields


Re: lookup replaces field lookup (v2023)

Posted: Wed Mar 06, 2024 6:22 am
by MichaelG

You should get the row data and format on your own. For example:

var row = ExecuteRow("SELECT DisplayField1, DisplayField2 FROM LookupTable WHERE LinkField = ...");
Field.ViewValue = Convert.ToString(row["DisplayField1"]) + ", " + Convert.ToString(row["DisplayField2]);

Re: lookup replaces field lookup (v2023)

Posted: Thu Mar 14, 2024 9:41 am
by crash

When I go back to edit my record it’s empty.


Re: lookup replaces field lookup (v2023)

Posted: Fri Mar 15, 2024 7:36 am
by MichaelG

Show you complete lookup settings and all the server event codes you are using.