Jump to content

Creating a simple find script


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

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

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 

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.

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
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

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

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?"  :-)

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.   

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?  :-)

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.  

Link to post
Share on other sites

This topic is 2062 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
  • Similar Content

    • By Tony Diaz
      How do I set a field with a value list item from a script, from a set of tick box values? .. or remove a value list item, but leave whatever else is there alone?
      Looks like GetValue with the name of the value list and the position # of the value, but I'm sure that also means that if I change that value list, I need to change any scripts that reference them by position # too..
      Something like detecting if a string is already there, and if not add it, surrounded by C/Rs, unless it's the first item entry?
      For the first time a field is set, I presume I could just Set Field (field ; "Value List Item"), and if there's only one entry/line in it, just clear it.  But if there's already a value there, I just want to select an additional one.
    • By emncwundy
      I have two iPads connected to FM server. For some reason one ipad (5th Gen running 13.5) will not complete the navigation scripts and shows error messages (no records match this find criteria), however the 7th Gen running on 13.1.1 works fine..... Issue has only begun after purchasing the second, newer iPad. I cannot for the life of me work out what is wrong, or how to troubleshoot and would love some guidance please!! Here is a screengrab of one of the scripts and related layout:
      fm go script issue.tiff Orders iPad layout.tiff
    • By PatrickDes
      Hello everyone,
      I have a Preference table with status options. The user can create a new status and through a script can assign a color (see attachment). The calculation is the following: 
      Allow user abort [off]
      Set error capture [on]
      Set variable [$start ;  value: Get ( ActiveSelectionStart )]
      Set variable [$end ;  value: Get ( ActiveSelectionStart ) + Get ( ActiveSelectionSize ) -1 ]
      Insert Calculated Result [ TextColor ( Middle ( Get ( ActiveFieldContents ) ;  Get ( ActiveSelectionStart ) ; Get ( ActiveSelectionSize) ) ; Get ( ScriptParameter ) ) ]
      Set Selection [ StartPosition : $start ; End Position : Send$ ]
      The ScriptParameter has the color values in RGB: RGB ( 237; 41; 190).
      The Status field is pulled into a Value List for the Product table. Is it possible, once the status is used in the Product table , to convert the text color into a conditional formatting? Is my approach wrong? I am trying to give the user some flexibility.
      Thank you for guiding me.


    • 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!
  • Who Viewed the Topic

    8 members have viewed this topic:
    jbrown  ggt667  Steve Martino  NLR  Wim Decorte  comment  rwoods  petergort 

×
×
  • Create New...

Important Information

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