You have three ways to pass information between scripts.
When you use Perform Script, you can specify a script parameter.
Perform Script ["script name",Parameter: Expression]
Where 'expression' can be any kind of calculation you need just like you'd define for a calculated field.
To retrieve this information in the performed script, use
You can use the set variable step to store a value in a global variable
Set Variable [$$VariableName, Expression]
Using two dollar signs at the beginning of the variable's name makes it global and ensures that the value can be accessed in other scripts
You can then refer to the information stored in $$VariableName in other script expressions such as:
If [$$VariableName = 5]
This used to be the only practical method for this task.
Use Set Field to store the information into a field so that the user and/or other scripts have access to the information.
Set Field [table::Field,Expression]
Frequently, it is most useful to make table::field refer to a global field in order to make it easy to refer to from any table/layout in your database file.
Method 4--Not recommended
You can use copy and paste script steps to temporarily store data in the operating system clipboard. This method has a number of problems and I don't recommend it.
You destroy the current contents of the clipboard which can inconvenience your users who may have already copied something to the clipboard and the copy, paste instructions only work correctly if they are present on the current layout.
I can't recommend a specific method for you from what little you describe in your post, but one of the first three methods should do the job.
I appreciate the reply, but it is kind of vague like you said. Maybe I can help by explaining a bit better.
From a data input form called "OrderEditForm" there is a button called ChoseCustomer.
In the script for the button:
Go to Layout ["Customer_Table" (Customer)]
Enter Browse Mode [Pause] //pause so that the user can look in the table to see if the customer is a repeat. If so, I want them to be able to select the customer (i.e. highlight the row) and then have that customer's "CustomerID" saved and sent back to OrderEditForm. If not, I want them to be able to add a new customer, select that customer and take it's "CustomerID" back to OrderEditForm.
I can't figure out how to code the "SetVariable" function to use the customerID of the selected row as the variable. Then, after that is done, how do you tell the script to "unpause" itself to finish passing the CustomerID back to the other form? Am I using the correct thought process in Set Variable or should I be using Method 1 to make it easier?
I know it is a lot, but I am having trouble understanding the basic logic that FP uses I guess. Is it possible to show me a few lines of sample code that would get me going down the right road...maybe turn on the lightbulb as it were? Thanks again.
Let's take the simplest question first: "how do you tell the script to "unpause" itself?"
When a script pauses, you should see two new buttons appear in the status bar: Cancel and Continue. If you click cancel or pres esc (windows) you cancel the paused script. If you click Continue or press the return key that is part of your number keypad, the script will continue to the next step. You can also setup a button to resume the paused script.
All three methods can do what you want. I'll select method 2 as it's probably the simplest to explain...
After your pause step, add the following steps:
Set Variable [$CustomerID,Customer::CustomerID]
Go to Layout [Original layout]
Set Field [tablename::CustomerID, $CustomerID]
Now change your customer_table layout to be a list view instead of a table view. Put a button in the body part of this layout and give it the Resume Script option. Label it "Select" or some such descriptive label.
Return to browse mode and test your script.
How it works:
When your script executes it displays the customer records in Customer_table.
If the user sees the customer record they want, they click the Select button. The mouse click makes that record the current record, the button starts up your script with the next step after the pause.
Now set variable will refer to the current record's customer ID field in order to save that value in the variable $CustomerID.
The final two steps return the user to the original layout.
You will need to edit the last step so that the correct field in your order form layout will get the customer ID number.
If the user needs to create a new customer record. They simply create the record and click "Select" and the results are the same.
Now some advice:
Don't pause your script in this case.
Instead make the above script a separate script and set up the Select button to perform it.
Edit your original to remove the pause step.
This way you don't have to deal with the situation where a user may accidentally cancel your paused script.
OOOOOOOOOOOOOOOOOOOhhhhhh! Got it. Thank you so much. I'll give it a try and see what happens.
This thing is a work in progress so I'm sure I'll be back with more questions. Is there a help line I can call for this?
You're using it right now I think :smileywink:
Is there a possibility that you could find the time to explain it using the Script Parameters as well? That way down the line I'll have an idea of how that thing works as well...
Here's the Script Parameter version that will do the same as our original example:
Don't use the Pause approach. Make the following code a separate script.
Go to Layout [Original layout]
Set Field [tablename::CustomerID, Get(ScriptParameter)]
Double Click your "Select" button while in layout mode or select it and choose Button Setup...
Select the Perform Script option and specify the above script as the script to be performed.
Down at the bottom of the Specify script dialog box is a text box labeled "Script Parameter" with an edit button to the right.
If you click Edit... you'll get Filemaker's standard specify calculation dialog and you can build whatever calculation you need. In this case, you just need to select the customerID field from the customer table.
Dismiss all the dialog boxes and you're done.
Both of these work magically. Now....
Here is what I want to write:
$LastName //for use in current layout
$$HostessID //for use in 3-4 different layouts
$LastName = Customers::LastName WHERE Customers::CustomerID = $$HostessID
Set Field (OrderEditForm::LastName; $LastName)
HostessID has been set using your above code. I want to define $LastName using code similar to that SQL statement in the script for the same button. Hopefully that makes sense...
What relationships do you have connecting your tables?
With the right relationship, you should need to copy this data over from the customer table. Instead, you should just refer to it. (Which will function exactly like your WHERE clause.)