Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

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

Recommended Posts

Posted

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

Posted

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 

Posted

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.

Posted

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
Posted

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

Posted

 

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

Posted

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

Posted

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.   

Posted

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

Posted

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

Posted

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.  

This topic is 3630 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.