Page 1 of 1
Filter a browse screen from a button
Posted: Thu Jul 22, 2010 1:08 pm
by antoniogarcia
I have a button in a edit screen.
I would like to launch a browse screen with a filter based in a field of edit screen.
Its posible that?
Thanks in advantage.
Antonio
Re: Filter a browse screen from a button
Posted: Fri Jul 23, 2010 2:55 am
by steven
Antonio,
Currently
Default Filter for Browse Screen only takes a string - not variables like getElementById (as of version 10.07.12)
eg.
button.jpg
a work around is this..
put this in the JavaScript tab of the button's form.
Code: Select all
function openB(){
/*
filter_string is the value you want to filter on.
(this string works exactly the same as typing a string into the search of a browse screen)
*/
filter_string = document.getElementById('customer_id').value;
form_primary_key = '146008847abeba';
ses_id = document.getElementById('session_id').value;
openBrowse(form_primary_key, filter_string, '', ses_id, '');
}
And put this JavaScript "openB()" in
On Double Click field of the button object.
Make sure you remove any form from
Form To Launch via Browse , otherwise the form will be opened instead of running the JavaScript function.
Steven
Re: Filter a browse screen from a button
Posted: Tue Aug 17, 2010 12:40 am
by dataman101
A long the same line ..
I'm experimenting with the concept of filtering all Form with an ID captured via the Lookup object on the INDEX form. I would need to pass in the ID as a variable and not a static value (as illustrated in the earlier posts).
Any idea on doing this via JS or using nuBuilder functionality.
Thanks
Re: Filter a browse screen from a button
Posted: Tue Aug 17, 2010 3:20 pm
by dataman101
Further research on this topic identified an opportunity and limitation. I would appreciate any elaboration if you have experience with it
The "Before Browse" box in the "Browse Code" tab in FORMS looks like the spot to apply:
Code: Select all
nuRunQuery(“CREATE TABLE #browseTable# SELECT * FROM table WHERE field = '#LookupFieldValueHashVariable#' “);
to apply filters to the data I want the end user to view.
But I need access to a Hash Variable populated by a Lookup Field on the INDEX Form to be passed to the "Before Browse". My attempts at this have failed.
Is this approach not possible because Field Hash Variables are not acceeible in "Before Browse" a stated in the Wiki-Appendix/Hash Variable?
http://wiki.nubuilder.com/tiki-index.ph ... uilderDocs
If this approach is not possible - are their any alternatives? NOTE: I have limited PHP / JS experience but I can follow examples.
Thanks
Re: Filter a browse screen from a button
Posted: Wed Aug 18, 2010 5:22 am
by steven
dataman101,
You can use hash variables in before browse.
To test that it converts the hash variable to the field's value you are wanting use nuDebug()
eg.
Code: Select all
nuDebug('#tra_delivery_address#');
This will put the value of
tra_delivery_address in the zzsys_trap table so you can check it.
Try putting
“CREATE TABLE #browseTable# SELECT * FROM table WHERE field = '#LookupFieldValueHashVariable#' “
in nuDebug()
Steven
Re: Filter a browse screen from a button
Posted: Wed Aug 18, 2010 3:57 pm
by dataman101
Thanks for the clarification.
I'm testing using the INDEX Form.
I'm using various field types (Lookup, Text, Drop Down) to try to create the HASH variable from the field_name entered but have not been able to see a live variable value when I nuDebug(#field_name#);
Example:
Create a Dropdown populated by "SELECT merchant_id, merchant_name FROM Merchant"
ALL tab 'Field Name' = merchant_id
nuDebug(#merchant_id#); is placed `On Blur` so it can trap the populated value after the field is populated and when focus is moved off the field.
The nuDebug() shows that the HASH variable is not getting populated and only displays the HASH variable name:
This is displayed in a browser window not zzsys_trap.
Debugging Output
#merchant_id#
Do HASH variables need to be declared for Objects? or is there a special syntax to creating them?
Thanks
Re: Filter a browse screen from a button
Posted: Thu Aug 19, 2010 2:34 am
by steven
dataman101,
The way a hash variable works is that before the PHP or SQL code is run there is a string replace done.
Replacing any hash variable with the variable value of the same name.
(If that variable is available -
http://wiki.nubuilder.com/tiki-index.ph ... uilderDocs)
Another way to see the variables available is... nuDebug(print_r($arrayOfHashVariables,true));
Hash variables don't need to be declared.
So
nuDebug(#field_name#); could become
nuDebug(hello world); and would create an error as it has no quotes around it.
I hope this helps.
Steven