If I want to find the records that in date range search (3/1/2015...5/10/2015)(or empty),
and the other conditions such as product_name is sth1 ( or empty ) and product_type is pt1 (or empty).
How to write the script ?
in this particular situation, I'd do it this way - see attached.
Leaving a field empty means "do not consider its content", therefore leaving all fields empty will find everything.
Leaving a date field empty but the other one not means, depending on the filled-in field, starting from .. or ...up to.
PS your biggest problem was not defining the popover search fields as globals.
You could build this up with a relationship.
Create some global-fields
This would be
TableA_Date_Start ≤ TableB_Date
TableA_Date_End ≥ TableB_Date
But comparative operators are performance killers!
You can create a formula field f_DateRange and use this cf to have dates Start to End listed in 1 Field:
FileMaker Custom Function:DateRange ( StartDate ; EndDate ; RangeLimit )
Relationship then would be:
TableA::f_DateRange = TableB::Date
Why not simply script the find? e.g.
Go to Layout [Invoices]
#show all, then start constraining
Show All Records
If [/* search date fields are not empty */]
Enter Find Mode [ no pause ]
Set Field [ Invoice::theDate ; dateBegin & ".." & dateEnd ]
Constrain Found Set
If [not Get ( FoundCount )]
#no point in proceeding
Exit Script 
#implicit else: without specified search date range, just use all records – i.e. do nothing
#apply same logic to other criteria
I was looking too far though I've overseen the most simplest way.
My approach would only make sense if this is used for any automated routine.
Right; “Real Men Don't Kill Coyotes Do Easy” …
Anyway, since we've no idea about the where, what and why of the user's requirement, your approach may be applicable here, too … WTFK?
But can you help me that modify the example (find.fmp) with the script and upload it?
Because I can't find what is Constrain Found Set
I'm a Chinese that just learn FM about one month. It's not so easy to me and my English is also poor.
Constrain Found Set takes the Find Request criteria and applies it only to records already in the existing found set. It refines the existing set, but does not search any records which are not already in the current found set before applying the new criteria.
Retrieving data ...