PDA

View Full Version : Grid Builder filter value


ABC123

Steve Wood
07-28-2004, 01:25 AM
what formula do you use in the Grid Builder Filter to set a Field value equal to a session variable?

Its not: Customer=Var-"user_name, because that is the wrong "session" variable. I need the internet session var as in: "? session.user_name". Obviously I would use this to restrict the grid results to those matching whoever logged in.

glenschild
07-28-2004, 01:34 AM
Steve

If you fire up the web application demo within v6 there is a page that shows how the login features should be used.

Regards

Glen Schild

Steve Wood
07-28-2004, 01:46 AM
I have the login function down pat, I'm talking about something different. That I see, the demo does not show how to use a session variable to filter a grid.

glenschild
07-28-2004, 02:49 AM
My apologies

In which case I do not have the answer

Regards

Glen

JerryBrightbill
07-28-2004, 05:45 AM
Steve

When you build the component, set a filter expression and check out the xbasic tab. You will see how the filter is build within the component. It may be something like this for a dbf file

tmpl.DBF.filter = "Customer_ID = 10"

Now place the comopnent on a page. When it is placed on a page, the point name will probably change to tmpl + the component name. Now you can get the filter - or change it with this value if the component is named "custlist"

tmpl_custlist.DBF.filter

You will see the actual pointer name on the page after the component is placed there. If you want to save it in a session variable named "filterexp", this line placed after the code that loads the component on the page will save it

session.filerexp = tmpl_custlist.DBF.filter

This will change the filter expression

tmpl_custlist.DBF.filter = "cusotmer_id = 20"

You can also take the expression part and modify it like any expression to use a variable. This variable can be froma session variable.

Jerry

Steve Wood
07-28-2004, 09:20 AM
Jerry;

Not quite following this. Indeed, if I go to the top of the A5W page that holds the Grid component, and modify it as (1) below I get a Grid that displays records for Customer=MYCUST. If I change the code to (2) below, or several variations I tried, I get the Grid error "Error 4 - not an open index".

(1)
"%a5
Delete Tmpl
DIM Tmpl as P
tmpl = a5w_load_component("Tracking")
tmpl.DBF.filter = "Customer=\"MYCUST\""
'Following code allows...

(2)
"%a5
Delete Tmpl
DIM Tmpl as P
tmpl = a5w_load_component("Tracking")
tmpl.DBF.filter = "Customer=session.user_name"
'Following code allows...

JerryBrightbill
07-28-2004, 06:15 PM
Steve

Probably the best method to show this is with an example. Attached is a zip file with 2 components and 2 web pages. They took about 15 minutes to build using the Alpha Sports sample database.

1. Open A5V6 and open the Alpha Sports database.
2. Create a new webproject.
3. Unzip the file into the new projects folder. For example, if you named the project "demo", the folder would be under the AlphaSports folder in

\Alphasports.WebProjects\demo.WebProject

4. Start the WAS.
5. Run the page "Customers.a5w" You will see the one field is actually a link field named "Get Invoices".
6. Select a customer and click on the link
7. This will open the CustInvoices page. Note that the link address will have values for "ID" and "Lname" in the address.

The code on the page "CustInvoices" takes the value in ID, if it exists, and converts it to a session variable named session.custid. The filter is then changed to take this value in an expression to get the right invoices.

The code also passes the customer name so it can appear on the invoice list page.

Jerry

Steve Wood
07-28-2004, 11:30 PM
OK, got it. Thanks Jerry!

So the mandatory piece of code is:

tmpl.DBF.filter = "Customer = \""+session.user_name + chr(34)

And it goes in every .a5w source that calls a grid that I want to filter.

When I get past my inability to access the server from remote (my other recent forum question), I'll share the URL to my WAS application.