Jump to content

Performing find in a script


DaCo

This topic is 3399 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I'm trying to create a script where one of the steps are to perform a find. I use "Find Records" in the group "Found Sets". I select a field in a table where I want for  records whicre empty OR records that contains "x".

 

When pulling down the list there is a selection of operators, but to me it's hard to see how to create this. Are the operators in the dropdown list the only allowed? Can I use f.ex. IF statements? I havn't tried since I'm not sure how to construct that.

Link to comment
Share on other sites

If I understand your question correctly, the answer is no, you cannot use calculations in a find request. You don't need to anyway. However, you do need to specify two find requests in this case; one to find records where the field is empty, and one to find records where the field contains "x".

Link to comment
Share on other sites

If I understand your question correctly, the answer is no, you cannot use calculations in a find request. You don't need to anyway. However, you do need to specify two find requests in this case; one to find records where the field is empty, and one to find records where the field contains "x".

 

Aha, I'd never figured that out myself. After a few experiments with/without quotes around x and with/without = I ended up with just an raw x. It works fine.

 

Thank you very much for your help and a Merry Christmas to you :king:

Link to comment
Share on other sites

Note that some of us recommend not using the Perform Find statement in the way that you are using it, with stored values in the Perform Find statement.

 

Instead, explicit scripted finds are much easier to read and troubleshoot.

 

Simple example:

 

Enter Find Mode  [ ] (no pause) 

Set Field [ contacts::State; "CA"]

Perform Find [ ] (no stored finds)

Link to comment
Share on other sites

Hooooold it. Sorry, it does not work anyway. I tested one find at a time by disabling the other, but when both are active, Find no. 1 are skipped ... or ... maybe the process is just hidden so I do not see the results of the search first.

 
In any case, as I am, with an end result that only contain Find no. 2.
 
Maybe I misunderstand you?. The steps in my scripts looks like this:
 
Go to Layout xyz
Show All Records
Perform Find [restore]
Perform Find [restore]
Export Records ...
 
The first find is: Product::Store [=]
The second find is: Product::Store [x]
 
I thought you meant that Find no. 2 would find in the found set, but is apparently not the case???
 
Am I doing this wrong?
Link to comment
Share on other sites

I use both Enter Find[] and Perform Find[restore].  All it takes the developer is a single button click to open the Perform Find to see what is stored.  And scripts are then two lines shorter for the single event.  

 

DaCo, you can't perform do it that way.  You need to use:

 

New Record/Request [] to enter your second find criteria because you are searching the SAME field.  As you have it, you are saying you want to find Store which is empty AND has an 'x' and since both can't be true, it will fail.  :-)

Link to comment
Share on other sites

Enter Find Mode  [ ] (no pause) 

Set Field [ contacts::State; "CA"]

Perform Find [ ] (no stored finds)

 

Ooops, I'm a novice. How do i change (pause) to (no pause)?

 

Next: How to define TWO criterias in "Set Field"?

Link to comment
Share on other sites

 

Perform Find [restore]
Perform Find [restore]
Export Records ...
 
The first find is: Product::Store [=]
The second find is: Product::Store [x]

 

There should be only one Perform Find step, with two stored requests. It should look like this:

 

post-72594-0-52072900-1419285617_thumb.p

 

 

Alternatively, as Bruce suggested, do:

Go to Layout [ YourTable ]
Enter Find Mode []
Set Field [ YourField ; "=" ]
New Request
Set Field [ YourField ; "x" ]
Perform Find []

Note that there is no need to show all records before performing a find;

Link to comment
Share on other sites

Partly inspired from this thread I've managed to get this to work, giving the expected result:

 

Go to Layout xyz
Show All Records
Perform Find [restore] >>>>>>>>>>> [=]
New Record/Request
Extent Found Set [restore] >>>>>>>> [x]
Export Records ...
 
Okay? ... and thanks to all :)

Alternatively, as Bruce suggested, do:
Go to Layout [ YourTable ]
Enter Find Mode []
Set Field [ YourField ; "=" ]
New Request
Set Field [ YourField ; "x" ]
Perform Find []

 

This is more elegant and easily understood than my own fudge. I will test and use it. Thank you.

Link to comment
Share on other sites

Hi DaCo,

 

I'd definitely go with either Bruce's approach, or LaRetta's (with Comment's clarification re needing two stored Find Requests in one Perform Find step).

 

Bruce's is not simply more elegant than the one that you got working for you (although it is that); rather, the one you got working is probably not actually working correctly, appearances to the contrary notwithstanding. The two stored finds in your method are, by themselves, fine, and making the second one an Extend Found Set step is also correct ("Extend Found Set" performs a Boolean OR, which is what you want).

 

The problem is that the New Record/Request step between these is executed while in Browse mode, so it's inadvertently creating a new record in your data table each time you run the script: not something you presumably intended. Unlike the "Show All Records," which, as LaRetta pointed out, is not really necessary here, this one is both unnecessary and deleterious. Minus those two steps you're probably OK. (There are many ways to skin the cat!)

 

Just to clarify, there are at least 3 ways to achieve a Boolean "OR":  (1) a New Request step while in Find mode (ala Bruce's script); (2) an Extend Found Set step (ala your script minus the two unnecessary steps); and (3) a single Perform Find with two stored requests (ala Laretta/Comment).

 

hth,

 

Mark

Link to comment
Share on other sites

One other advantage of the "Enter Find Mode / Set Field" construct is that you can enter Find mode first, and then go to the target layout. This can have a noticeable effect on a hosted file over a WAN, with lots of records, and/or record-level security. E.g. your script would look like:

 

Enter Find Mode

Go to Layout     // <---- do this AFTER Find Mode

Set Field

Perform Find

  • Like 1
Link to comment
Share on other sites

Yes Tom!!  And that's one of my favorite new techniques!  I see that I'll now have to change my approach and use Enter Find Mode[] instead!  Thank you for mentioning this!!  :laugh2:


Perform Find [ restore ] just took a nosedive in my book!

Link to comment
Share on other sites

Hmmm, this seems to develop a little embarrassing. It is clearly demonstrated highly competent answers I get, but at my stage, I have fundamental problems in testing them. Goofy among experts if I may say so.

I have read and read (Eg http://www.filemaker.com/help/11/fmp/html/scripts_ref1.36.39.html), but nowhere am I get taken by the hand and guided step by step on how "Set Field" operated. In order to arrive at something that is similar to the Comment's line Set Field [Your Field; "x"], I have - after many attempts - reached the following steps:

  • "Set Field" from the left pane
  • Specify target field (Selecting Product::Store)
  • Specify Calculated result (entering "x")
When i run the script I get "The provided find criteria is not valid ..."
Link to comment
Share on other sites

Where is the script? Attach an example file or at least a copy of your complete script.

 

The script is in FM 11.0v4 inhouse; not published or connected online in anyway.

 

My script:

 

Go to Layout [original layout]

Enter Find Mode []

Perform Find []

Set Field [Product::Store; "x"]

 

The construction of Set Fields was described in my previous post.

Link to comment
Share on other sites

You really need to read FileMaker Help - it is in the menu of your FileMaker program - to the right Window.  This is basic stuff under finding.  Sorry to be blunt.


You are not even reading the perfect examples given you.  See post #11, 4 or 8 for example.  Are you in same sequence?  No.


How can you begin with Go To Layout [ original layout ] when you haven't gone anywhere at the beginning of your script yet?


How can you have the Set Field[] AFTER the Perform Find?  

  • Like 1
Link to comment
Share on other sites

Ach you Lieber. I realize (better late than never?) that the representation of my script was dumber than strictly necessary. A little forethought on my part would / should have spotted the errors you point out.

Now I will fix it and hope that I will not need to ask again. My problem is that I AM and always WILL be a novice. It often takes weeks or months between that I need to do something like this. Going to a course and / or reading thick books will be wasted, since I never get reprocess experience and routine in practice.

Link to comment
Share on other sites

One other advantage of the "Enter Find Mode / Set Field" construct is that you can enter Find mode first, and then go to the target layout. This can have a noticeable effect on a hosted file over a WAN, with lots of records, and/or record-level security.

 

Wasn't it concluded that Freeze Window would serve just as well?

Link to comment
Share on other sites

A combination of #8 and #11 works perfectly (thanks to others too):

  1. Enter Find Mode []
  2. Go to Layout [original layout]
  3. Set Field [Product::Store; "="]
  4. New Record/Request
  5. Set Field [Product::Store; "x"]
  6. Perform Find []
I am really sorry to pull the thread down to an unnecessary low level. Next time I will think a little more before I ask a question :hmm:
Link to comment
Share on other sites

You probably want to select an actual layout though.

 

Actually I only have two layouts: Products and Upload. When I click for Specify only Upload are selectable ... and Original layout offcourse. I must admit that I don't know what Original layout refers to (shame on me - I MUST read much more in Help :idot:

Link to comment
Share on other sites

If you have two layouts, two layouts are selectable.

If your script goes to other layouts, or perhaps multiple layouts, then go to original layout does what it says.

Yes. You should read the help.

Link to comment
Share on other sites

If you have two layouts, two layouts are selectable.

 

I'm sorry, Bruce. When I click for Specify only Upload are selectable ... (= not present in the box)

 

My script is supposed to work in layout "Products" and it does very well, but if "Upload" is active I would like the script to switch to the layout "Products" but it doesn't do that in real life.. It's a little difficult to select it since this is not selectable.

Link to comment
Share on other sites

Actually I only have two layouts: Products and Upload. When I click for Specify only Upload are selectable 

 

If you only have two layouts and one is Upload and it displays as an option then the layout you are ON must be Products, no?  You really MUST read Help on searching.  Is the Products layout saved yet?  Is it in another file?

Do you need to GO anywhere at all?  If you are on the layout you need to search then remove that line.  We are now on 26 posts for something that should have taken five.  Please spend a bit more time thinking through your needs and trying our suggestions.

Link to comment
Share on other sites

My problem is that I … always WILL be a novice.

 

Not if you download this (the FileMaker Training Series) and work your way through the exercises. "Help" is good for answering targeted questions, but to get the fundamentals, some sort of structured training is better. I guess you now know what you've got planned for your holiday down-time.  ;)

 

I think one of the things that is tripping you up is that some of FileMaker's script steps act very differently depending on what mode you're currently in, hence the critical importance of getting script steps in the correct sequence and always knowing which mode you're in at each point in your script.  

 

For example, New Record/Request creates a new Find Request (Boolean "or") in Find mode, but adds a new record to your data table in Browse mode. Pretty different, eh?  So, how do you know which mode you're in?

 

Obviously, Enter Browse Mode and Enter Find Mode will each do what they claim, and subsequent steps will act in the respective mode. But there's more to it than that, which brings us to another step that does different things in different modes: Perform Find. If you're in Browse mode, this step (with the "Restore" option checked) will perform a stored find without ever leaving browse mode. If, otoh, you're in Find mode, then this step will execute the search you've just set up (i.e., with one or more Set Field steps while in Find mode) and return you to Browse mode. Either way, at the end of a Perform Find step, you should expect to be in Browse mode.

 

Lastly, Set Field allows you to specify a search criterion if you're in Find mode, but actually edits the data in your current record if you're in Browse mode. Again, pretty different!

 

Hope the FileMaker Training Series helps. I probably speak for everyone who's responded in this thread that we didn't have an official training series back when we started out, so you've got a leg up as far as having something to help you with your learning curve.

 

hth,

 

Mark

Link to comment
Share on other sites

One other advantage of the "Enter Find Mode / Set Field" construct is that you can enter Find mode first, and then go to the target layout. This can have a noticeable effect on a hosted file over a WAN, with lots of records, and/or record-level security.

Wasn't it concluded that Freeze Window would serve just as well?

Interesting. Do you have a link handy to that discussion? It seems to me I did try using Freeze Window to fix some problems with Find scripts but it's been awhile. For example, our users would sometimes see "<no access>" on the Find layout, because it went to the layout in Browse mode.

 

Another reason to go to Find mode first is when you have script triggers on the target layout, or on layout exit of the starting layout, that you don't want to trigger.

Link to comment
Share on other sites

Aha. Thank you, sir. So Freeze Window works this way in 13, but not in 12, am I reading that correctly?

 

A few of us developers in my office have Windows 7 and FM13, but most of our users are stuck on Windows XP and FM12. Sad but true.

Link to comment
Share on other sites

This topic is 3399 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.