NetTalk Central

NetTalk Web Server => Web Server - Ask For Help => Topic started by: DonnEdwards on June 29, 2021, 06:13:40 AM

Title: Field Lookup Function
Post by: DonnEdwards on June 29, 2021, 06:13:40 AM
I have a NTWS browse form (Invoices) that I want to filter by customer number. So I created a Memory form "Filter_Invoices" that has browseInvoice as a child form.

At the moment I can display the Customer number in the memory form's header, by doing the following:

Heading: 'Invoices for Customer #' & p_web.GSV('cus:CustomerId')

What I really want is
Heading: 'Invoices for ' & Lookup('CustomerName','Customer','CustomerId='p_web.GSV('cus:CustomerId'))
so that the heading is shown as "Invoices for Acme Widgets Inc" or whatever.

Visual Basic has a function called DLookup("Field","Table","Where clause") and the Where clause can be a whole big SQL statement. I'm looking for something a little more modest. Does such a function exist in Clarion/NetTalk, or will I have to write one?

All suggestions welcome.
Title: Re: Field Lookup Function
Post by: Bruce on June 29, 2021, 07:08:46 AM
Hi Donn,

>> 'Invoices for ' & Lookup('CustomerName','Customer','CustomerId='p_web.GSV('cus:CustomerId'))

It's not quite as simple as that, but it's not terrible.

A) in the form heading field put the name of a local variable - ie somethign you create in the data pad. like donn:header

B) in the embeditor go to the
Heading  Routine

this is where you can set donn:header to whatever you want.

So, now you have a couple options to load the related record, and get the customer name. first the obvious;

Access:Customer.Openfile()
Access:Customer.Usefile()
cus:CustomerId = p_web.GSV('cus:CustomerId')
Access:Customer.Fetch(cus:idkey)
donn:header =  'Invoices for ' & cus:CustomerName
Access:Customer.Close()

If you have myTable then it's a bit simpler;

mt  myTable
  mt.get(Customers,'id',p_web.GSV('cus:CustomerId'))
  donn:header =  'Invoices for ' & cus:CustomerName


there's also a p_web._LoadRecord method
  p_web._Loadrecord(Customers, cus:IdKey,p_web.GSV('cus:CustomerId')
  donn:header =  'Invoices for ' & cus:CustomerName

which would also probably work (not tested though)

Cheers
Bruce

 


Title: Re: Field Lookup Function
Post by: DonnEdwards on June 29, 2021, 09:26:38 AM
Thanks Bruce! I'll give each method a try.

Edit: I discovered that loc:Heading was already in use. I guess that's why your example didn't use it. ;-)
.OpenFile() is a typo. Should read .Open()
Otherwise, code works perfectly.