Page 1 of 1

How to realize lookup of two or more data

Posted: Tue Apr 05, 2022 1:32 pm
by hujunhong
Cp_Invoice.png
Cp_customer.png
Cp_contact.png

1,What code can I use when I choose cp_Invoice_contact_id
cp_Invoice_customer->Cp_customer_name
cp_Invoice_address->Cp_customer_address
cp_Invoice_phone->Cp_contact_phone

2,What code can I use when I choose cp_Invoice_contact_id
cp_Invoice_date -> today's date

Re: How to realize lookup of two or more data

Posted: Tue Apr 05, 2022 1:40 pm
by kev1n
Hi,

You can use PHP in the After Browse event for that Lookup to populate these additional fields.

The function you need is nuSetFormValue

Re: How to realize lookup of two or more data

Posted: Tue Apr 05, 2022 2:05 pm
by hujunhong
kev1n wrote: Tue Apr 05, 2022 1:40 pm Hi,

You can use PHP in the After Browse event for that Lookup to populate these additional fields.

The function you need is nuSetFormValue
Thank you Kevin
2,cp_Invoice_phone_id->Cp_contact_phone
nuSetFormValue('cp_Invoice_phone',nulookupRecord()->Cp_contact_phone);
it is ok
but 3 and 4 cp_Invoice_customer and cp_Invoice_address is not
I tried nuSetFormValue only in the same table, but my information is two tables, how to use code?

Re: How to realize lookup of two or more data

Posted: Tue Apr 05, 2022 2:18 pm
by kev1n
hujunhong wrote: Tue Apr 05, 2022 1:32 pm 2,What code can I use when I choose cp_Invoice_contact_id
cp_Invoice_date -> today's date
Use this JavaScript in the lookup's LUJS field:
setdate.png

Re: How to realize lookup of two or more data

Posted: Tue Apr 05, 2022 2:26 pm
by kev1n
Can you show the SQL of the lookup form?

Re: How to realize lookup of two or more data

Posted: Tue Apr 05, 2022 6:05 pm
by hujunhong
kev1n wrote: Tue Apr 05, 2022 2:26 pm Can you show the SQL of the lookup form?
sql.png

Code: Select all

SELECT
 Cp_Invoice.*,
    Cp_contact.*,
    Cp_customer.*

FROM
    Cp_Invoice
        JOIN Cp_contact ON Cp_Invoice.cp_Invoice_contact_id = Cp_contact.Cp_contact_id
        JOIN Cp_customer ON Cp_contact.Cp_contact_customer_id = Cp_customer.Cp_customer_id

Re: How to realize lookup of two or more data

Posted: Tue Apr 05, 2022 6:20 pm
by kev1n
nuLookupRecord() will only return the the fields of the table used by the Lookup. You can add an additional query to retrieve the other values.

Example:

viewtopic.php?p=15921#p15921

Re: How to realize lookup of two or more data

Posted: Wed Apr 06, 2022 5:23 pm
by hujunhong
kev1n wrote: Tue Apr 05, 2022 6:20 pm nuLookupRecord() will only return the the fields of the table used by the Lookup. You can add an additional query to retrieve the other values.

Example:

viewtopic.php?p=15921#p15921
thank you kevin.problem solved