Change where in the grid application

onApplicationInit is run one time when the app is loaded,

you only have to be sure that [where_filter] is declare, you can even declare at login if you want

reassing [where_filter] when needed, without using sc_select_where (add)

I just try it and it work fine

it can’t possibly work.
when you enter the app you would have the wrong filter and not the initial one

If you define the WHERE filter before entering the app you are right

so in this case define [where_filter] at login and use it at a session variable

sorry but you certainly do not solve the problem, I set it at login but then until I login again the value remains that of the filter.
it is definitely not the right solution, or rather it is not the result I want to do.

Don’t set it at login, create it at login with an initial value of [where_filter] = “true”;

Set it in your search button

we probably didn’t understand each other, mine is a normal Grid and the search is the standard search of SC


in your GRID set your SQL to: SELECT * from table WHERE [where_filter]

Set [where_filter] = “field1 = 10” or [where_filter] = “field2=80” in the onValidate of the search and pass it as a parameter to your grid

It work, I just try it

ok now in the same application go back to the grid and tell me which filter is applied?
not the original but the ones you set with the last search!

I don’t know the flow of solutions, but if you need to reset the WHERE after acceding your GRID, just set it back to the original value. Do it in onRecord, I know that it will be executed on each line, but at least it will be reset to whatever you want

if there is no macro of SC to reset the where is not possible, the search button inside of SC creates the WHERE by adding it to the existing one and it is impossible to delete or overwrite it, there is no way.
it would be nice to have an opinion from someone on the SC team

I hope I can help you. I open each grid with the search query active = 1. Via advanced search I can adjust that again to for example active = 0, or delete the search result completely. Are you looking for something like that?

yes I would like to totally rewrite the where

Maybe this helps: Start filter grid application

sorry but for me it is never a good idea to touch the product code from sc.

I do not edit the source code in the generated php file. My grids have been working this way for a year.


I assume you mean the advanced search?

If so what I tend to do is the following:
I create custom search fields in the search section. I then in my grid applications onScriptInt create a custom where clause variable called [custom_where].
Then I just assign it a value like “WHERE field2=80” and add it to the where clause using sc_select_where(add).

I would also remove the original where clause from the grid and move it in to the grid onScriptInt event.

So your code would look something like this:
Grid onScriptInt event:

if([search_was_done] != 1)
[custom_where] = “WHERE field1 = 10”;
[custom_where] = “WHERE field2 = 80”;

sc_select_where(add) = [custom_where];

[search_was_done] is assigned a value in the onApplicationInt of 0.
You then give it a new value in the search event onValidate of 1.

onScriptInt it is executed every time the grid opens, even after a search, therefore it would always be added, if you change the variable value [custom_where] =1 after the search, when you return to the application in the same “session” it always remembers the filter set by the search.
i have a I have a dashboard where I would like to have an initial filter (last 7 day) and then be able to perform searches that exclude the initial filter (last 15 day)

“through the search button off grid I want to change this filter, not add filter but change like”

From what you asked you want to do the following:

  1. When the application loads there is a initial filter.
  2. When the search is done the filter is updated.

My answer accomplishes both of those tasks.

From your reply it looks like the above quote is not what you want to have happen.
From what I can tell you want the following to happen:

  1. You want a initial filter that will always be in place on the main grid.
  2. During the search it self you want it to ignore the initial filter (7 days) and perform the search on a new filter (the 15 days one) while not changing the filter on the grid.

as I said I don’t want to add a clause, but completely remove the initial one from the table.
if I do as you wrote that macro sc_select_where(add) adds to where it does not replace.


I assume then you didn’t read the full post I made. I specifically addressed this issue:

There you can see me saying to remove your current where clause and add it in the onScriptInt event with a if statement that checks whether or not a search has been done.

This way it will either use the one where clause or the other.