Custom Filter on Button click

How can i tell SC to change the filter on a form when a button is click?

What i am facing now, it prompt a blank ‘OK’ button page, and nothing is filter.
I would like to get ride of the button goto a different form.
What i expect is simple, the page return 5 rows now (based on initial filter), then when the new button click, it return 3 rows (based on another filter logic)

Thanks for the guidance.

There are several options, but you can use a global variable to change the where clause or use sc_macro’s. At the end of your script of the button do a sc_exit(sel);

It will prevent the ok button and restart your application.

[QUOTE=aducom;28529]There are several options, but you can use a global variable to change the where clause or use sc_macro’s. At the end of your script of the button do a sc_exit(sel);

It will prevent the ok button and restart your application.[/QUOTE]

hi Albert, thanks :slight_smile: it worked.
But how to manipulate the filter? alter the result return in a form on a custom PHP button click?

i tried to execute following code in my PHP button

{sc_where_filter} = “”;
sc_exit(sel);

what i expect was to return all result, end up there is no different/chances occurred.

No that won’t work as your application will startup again, all fields willl be initialized. So you can set a global variable and fill that with the initial filter in the onapplicationinit or (that’s how I often do it) set it in the onexecute event of the menu calling the application. Then in the onclick event you change the global variable and start the application. Be aware that onscriptinit is fired too, so don’t set your global there.

i am quite concern to set a global. Is there any App level scope?
coz if my global var set as [sqlFilter] and will it impacts if i have another app with same global var name?

also, what’s the macro to change button lable?

I understand your conceirn, but we do it that way. In fact we declare all globals in the logon procedure so that we don’t make a mess elsewhere. We don’t like the idea of creating them ‘somewhere’ in the application. If you call an app using it you can get obscure errors like ‘global xxx not found’. Even if you are using plain php you will run into similar issues, you can set scope but it needs to be bound to a session to be able to retrieve.

I don’t know of any macro to change the button label.

can u show me how to declare them during logon procedure?
I am not quite understand.

[QUOTE=weilies;28549]can u show me how to declare them during logon procedure?
I am not quite understand.[/QUOTE]

All global variables we use are not declared in the application where they are first used, i.e. as in or out, but we declare them in our logon application. As this is our first application that start, after successful login (onvalidate) we declare all our global variables and initialize them if necessary. If you don’t have a logon application you can consider doing it in the main application, the first that is fired to start your application. It’s standard SC method:

[glob_patid]=0;
[glob… etc.

weilies,

An alternate approach you may want to consider, that I use. Instead of globals, I establish session variables “dedicated” to a particular app. for instance:

$_SESSION[‘my_app’][‘retry_count’] = 10;

This way, I am “manually” enforcing scope, and feel a little less fear that it will be used accidently somewhere that it shouldn’t.

It is not necessarily more or less safe than Albert’s approach, the most important thing is to choose an approach and stick to it.

Dave