Jump to content
Sign in to follow this  
Tron50

Creating a simple find script

Recommended Posts

Looking for some help with creating a simple script.  We have a database of inventory items, when the user enters a layout to search for the item, he is presented with a screen that has the item field on it and a button that performs a script.  The idea is to simply perform a lookup of the number that is entered in the field and then open the next layout that shows the table view with only those items with that item no.  I have created a script but something is missing obviously, what do I need perform the find on what is entered in the field, or is it possible to create a variable just for that search and then do a search and go to the layout.  Attached is a picture of the script, any help is appreciated as I'm very new to Filemaker

 

Thanks

Report Script.tiff

Share this post


Link to post
Share on other sites

Thanks Lee,

 

When I create the following script following the instructions in the link you provided I do it as follows :

Go to Layout ["JPF_reportsbyitems"(itloca)]

Enter Find Mode [Pause]

Perform Find []

Go to Layout ["JPF_findmyitemsresults" (itloca)]

  

 

This is what happens, the script goes to the layout, it has one field on it and it goes into find mode.  The problem that happens is when it goes into find mode it does not allow me to enter the item number, it automatically goes into find mode and grays out the field, so when it goes into the last layout it shows nothing as it is trying find part numbers that have nothing in it.  

 

Perhaps I'm missing something in this script setup

 

 

When entering a find, do I have to create a variable and then within the script tell the find to search for field = "input".  I'm kinda confused on how to get 

Share this post


Link to post
Share on other sites

Create a global field to hold the searched item no, then write a script like

Set Variable [ $searchTerm ; Table::gSearchField ]
If [ IsEmpty ( Table::gSearchField ) ]
  Exit Field
End If
Enter Find Mode [ no pause ]
Go to Layout ( YourSearchLayout ( YourTable ) ]
Set Field [ YourTable::itemNo ; Table::gSearchField ]
Set Error Capture
Perform Find [ no restore! ]
If [ not Get ( FoundCount ) ]
  Go to Layout [ original ]
  Show Custom Dialog [ "No matches found for " & Quote ( Table::gSearchField ) ]
End If

When entering a find, do I have to create a variable and then within the script tell the find to search for field = "input".  I'm kinda confused on how to get 

 

Since in this case the search field is a global field, you can reference it from anywhere. Alternatively (e.g. if the field is non-global and/or you need to perform calculations on it or refer to it repeatedly), it may be more effective to put its value into a variable:

Set Variable [ $searchTerm ; Table::gSearchField ]
If [ IsEmpty ( $searchTerm ) ]
  Exit Field
End If
Enter Find Mode [ no pause ]
Go to Layout ( YourSearchLayout ( YourTable ) ]
Set Field [ YourTable::itemNo ; $searchTerm ]
Set Error Capture
Perform Find [ no restore! ]
If [ not Get ( FoundCount ) ]
  Go to Layout [ original ]
  Show Custom Dialog [ "No matches found for " & Quote ( $searchTerm ) ]
End If

Use the == operator if you need to find an exact match for your search term, i.e. Set Field [ YourTable::itemNo ; "==" & $searchTerm ]

 

Alternatively, create a self-join relationship between the global field and itemNo; then use Go to Related Record [] instead of a search, or display the matching records in a portal; or do both.

Share this post


Link to post
Share on other sites

When entering a find, do I have to create a variable and then within the script tell the find to search for field = "input".  I'm kinda confused on how to get 

 

Hi Tron,

 

When in Find mode, record data does not exist.  So once in find mode, you can't ask for a record's values to use in the find. Instead, you must collect the values before entering Find mode by storing the values in a script variable first, similar to single script of:

  1. On Customers layout, set a script variable with the CustomerID.  
  2. Go to Invoices layout and Enter Find Mode.
  3. Set the Invoices::CustomerID with the script variable.
  4. Perform the Find

If you require User input, use global fields so they can enter the values they wish to find.  Globals values are still available in Find mode so there is no need  for step 1 above and step 3 would be changed to setting the Invoices::CustomerID with the global field values the User entered instead.

 

The problem that happens is when it goes into find mode it does not allow me to enter the item number, it automatically goes into find mode and grays out the field

 

In layout mode, check that field.  It probably has disabled the ability to enter that field in find mode (check Inspector > Data tab > Behavior > Field Entry and see if 'find' is checked.  If that is not it then you may not have permissions to search that field (check File > Manage > Security).  Or the field may be a summary or container field (neither being searchable).

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for the explanation, here is what I have done and it works:

 

 

Set Variable [ $searchterm; Value:Gvariable::gitemno ]

If [ IsEmpty (Gvariable::gitemno) ]
End If
Enter Find Mode
[ ]
Go to Layout [ “JPF_reports1” (Itloca) ]
Set Field [ Itloca::Item_no; Gvariable::gitemno ]

Set Error Capture [ On ]

Perform Find [ ]
If [ Get(FoundCount) = 0 ]

Go to Layout [ “JPF_reports” (Locator) ]
Show Custom Dialog [ Title: "No Matches for"; Message: Gvariable::gitemno; Default Button: “OK”, Commit: “Yes”; Button 2:

“Cancel”, Commit: “No” ]

End If 

 

What is the best way to create an array in Filemaker rather than declaring each variable so I can create an array list with a simple incrementing script?

Thank you for the help in wrapping my brain around this

Share this post


Link to post
Share on other sites

 

Set Variable [ $searchterm; Value:Gvariable::gitemno ]

If [ IsEmpty (Gvariable::gitemno) ]

Exit script

End If

Enter Find Mode [ ]

Go to Layout [ “JPF_reports1” (Itloca) ]

Set Field [ Itloca::Item_no; Gvariable::gitemno ]

Set Error Capture [ On ]

Perform Find [ ]

If [ Get(FoundCount) = 0 ]

Go to Layout [ “JPF_reports” (Locator) ]

Show Custom Dialog [ Title: "No Matches for"; Message: Gvariable::gitemno; Default Button: “OK”, Commit: “Yes”; Button 2:

“Cancel”, Commit: “No” ] <-- what are your choices here for?  There should be no options or the User options should be captured using Get ( LastMessageChoice ) ..

End If 

 

There is nothing wrong with creating multiple script variables.  But that is not what you have - you are using a global FIELD gItemno in a TABLE Gvariable, right?  Why are you naming a table Gvariable?  I am not convinced you understand the differences yet.  What are the other values where you feel you want to create an array?  There are many times you will want an array but I do not see it here.  You can create name/value pairs in script or global variables (use global variables sparingly):  

 

http://filemakerstandards.org/pages/viewpage.action?pageId=557462

Share this post


Link to post
Share on other sites

And what do you mean about 'incrementing script'?  Are you asking about creating a loop for some reason?  We need to understand the WHAT of your request, similar to:

 

The WHAT "I need to enter multiple values in the find" and then the HOW "so how do I create an incrementing script?"  :-)

Share this post


Link to post
Share on other sites

Hey LaRetta,

 

I did not plan to implement any array in the script highlighted, I was only asking for educational purposes.  The table Gvariable contains a few fields set as global variables so I referenced the one I needed to use for user input and provided that for the find against the itloca table.  You are correct there should be no options for the user with the No since if no found set of records is located only the user message should be displayed.

 

Thank you for the insight, always happy with the suggestions and input.   

Share this post


Link to post
Share on other sites

Okay, cool.  But it will be important that you call things by their correct term.  You can not have a table which references variables.  You have a table which references global fields ... completely different animal.  So be very careful which word you use here or you might get unexpected answers from developers when you say you have a 'variable' when you mean you have a 'global field.'

 

Your said:

The table Gvariable contains a few fields set as global variables

 

What you mean is:

The table Gvariable (should be called a globals table) contains a few fields set as global fields.  If you begin life in FileMaker calling something this critical by an improper name, you will have trouble adjusting later.

 

On the Custom Dialog, it will only come up if there are no records.  What I was trying to explain that, if no records, they do not the different button options, only the OK button since it is just informational.  

 

Fun stuff, huh?  :-)

Share this post


Link to post
Share on other sites

Yep it sure is.  Slowing starting to get the hang of it.  And thanks for the correction I don't mind, I'd rather get it right then continue making mistakes.  I may be asking more questions if you don't mind

Share this post


Link to post
Share on other sites

I don't mind at all - I try to respond when I can and that is the purpose of this forum after all ... helping people with their FileMaker questions.  There are many great developers here who will help as they can.  

 

If additional questions involve a different functionality then a new thread would be warranted.  Just select the forum that you think best fits your need.  If you are incorrect, Lee will catch it and move it for you; no worries.  Just do the best you can.  

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Similar Content

    • By Agnes Riley
      I'm getting "The file "" could not be opened. Either the host is unavailable, or the file is not available on that host."
      This happens when a script runs. Not a new server, no new files. The file is actually open in the background. The file reference is just "file:".
      I restarted the server. Didn't fix it.
      FMS18.03
      It's apparently intermittent. I copied all the script steps to a new script, then it worked 3 times, but couldn't find the file for the 4th time.
      Any ideas?
    • By nsdodgers
      Hello, I have a number field where I want the user to be able to enter things like:
      42 (only item 42) 12+82 (only items 12 and 82) 1-5 (items 1 through 5) 31,33,35,37 (only items 31,33,35,37) So I am need of a way for filemaker to deal with the operators '+' '-' and ','
      Do you have any advice on how I can separate out the item numbers?
      Thanks!
    • By stuee
      Hi, in the same table i have 3 fields.
      Name   (this is the drop down of names)
      Timecompleted
      Datecompleted
       
      I want to have so when a person selects their name in the drop down to complete this task that the current time stamp is filled in.
      I cant seem to get it to do that but ideally i would like just one field with timestamp   15:30  21/02/2019
       
      I also have about 50 tasks which people can do so hoping a more simple way instead of a fll script for each one.
       
      Hope that made sense
       
      Cheers
    • By Oyseka
      Hi all, I need to go to different layouts depending on device and parameters and while the script functions fine for the desktop I can not get it to go to the correct layout in the iPhone. What am I doing wrong.
      Sorry all, found my level of stupid and answered it myself.
    • By Monarch
      Hi everyone!
      I have a text field, with each sentence separated by ¶ .
      I would like to create buttons for each line in this field, so that I can copy each line individually (and paste manually in different application for example)
      I assume that it's easy to do in calculation with GetValue, and make a script using Get (ScriptParameter) = line number in that field, for each button. ( I ll need only 7-10 lines max).
      1. I can't figure out what script function I need to use to make a selective copy...
      2. If one of the option is Set Selection function - how would it work in my case?
      Thank you!
×
×
  • Create New...

Important Information

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