1 2 Previous Next 29 Replies Latest reply on Mar 3, 2011 2:48 PM by LawnGuy

    Editing scripts



      Editing scripts


      I am not to good with scripts yet. I want to be able to create a button on contacts layout that would create a record from a related file, from the contacts module or database. I've found a related script from a pre made template and copied it knowing that I would need to edit the script to use in my setup. But I can't edit the script any way that I can see. If I try to edit the only thing I can edit is the field but this particular script is more than a simple field. 

      This is script I copied;  Set Field [Contacts::Temp Data; Contacts::Contact ID]

                                    Preform Script ["Create New Service Order from Contacts" from file: "Service Orders"]

      This is what I think I want, but not sure how to write it;  Set Field [Contacts::Temp Data; Contacts::Full Name]

                                                                               Preform Script ["Create new service agreement from contacts" from file "Service Agreements"]

      I'm missing something here. I've done this before but only needed to adjust singular field that didn't mess with rest of script.

        • 1. Re: Editing scripts

          When you click the Set field step in your script, you'll see two specify buttons appear in the lower right corner. Click the lower one to change Contacts::Contact ID into Contacts::Full Name.

          With the perform Script step, you can select it and click Specify or just double click it to bring up a dialog where you can select both the script and the file where it is located. (use the drop down at the very top to select the file, if it isn't listed, select Add FileMaker Data Source and you'll get another dialog where you can find and select the file.)


          • 2. Re: Editing scripts

            In the specify script dialogue box it allows me to select the related file but then the larger name box is highlighted, what goes in there? I can't select OK as it is dimmed, I'm guessing until I put something in the name box, but it doesn't allow me to type there, the only place I can type is Optional script parameter.

            • 3. Re: Editing scripts

               The drop down list will list all script folders in the selected file. You can select a specific folder or "Show All". You can filter the list of scripts and folders shown in the main box of this dialog by entering text in the box next to the magnifying glass.

              However you use these two fields to manipulate the list of available scripts, once you see the script you want listed, click it once to select it and then dismiss the dialog by clicking OK.

              • 4. Re: Editing scripts

                I have found that the related file has no scripts to manage, when I create a new record script for related file I then have something to choose from in the above mentioned name box. But I still am not able to do what I'd like, which is, from contacts I want to hit button that will create a new record in the related file, that is visible and then inserts all the data from current contact into appropriate fields on related file record. What would be your suggestion.

                • 5. Re: Editing scripts

                  It depends on the relationships, if any you have established between the two tables. In Manage | Database | Relationships, it's possible to link a table in one file to the table in another.

                  If you have a relationship like this defined in the file for Table 2:

                  Table1::PrimaryKey = Table2::ForeignKey

                  You can defined looked up value auto-enter field options for each field in Table2 that needs to copy data from a matching record in Table1. Then your script can pass the value of PrimaryKey in that optional script parameter to perform a script you define in File 2:

                  Go To Layout [//select layout to Table2 where you want to display the results of this operation]
                  New Record/Request
                  Set Field [Table2::ForeignKey ; get ( ScriptParameter ) ]
                  Select Window [CurrentWindow]

                  The last step brings the window to file 2 to the front.

                  Another option that does not require a relationship is to write a script In File 2that uses Import Records to import records from File 1 into Table 2 in File 2.

                  Then a script in File 1 isolates the current record in a found set of one record, then uses Perform Script to perform the script in File 2 that uses Import Record to import the data.


                  • 6. Re: Editing scripts

                    I have a relationship set up between contacts file & related file, however I've only linked the 1st & last names or full name. Should I link all of the fields that are available in the related file to their matches in contact file?

                    • 7. Re: Editing scripts

                      Do not link all the other fields. If you can possibly set this up by linking with a serial number field, it will be much safer for you. Names are not unique and people change their names from time to time.

                      • 8. Re: Editing scripts

                        I don't want to do that if I can help it. I run less than 1000 accounts and with middle initials I can keep them unique.

                        I'm still missing something though, maybe it's because I'm not using account numbers. I've set it up so that each of the fields in table 2 are auto lookups from table1. I set button on table 1 to perform script, I specify from table 2 the script that I made for this button. The script that I set up in table 2 reads like this

                        Go to layout [original layout]  

                        New Record request

                        Set Field [(table 2)::First Name[GetField ((table1)::First Name)]]

                        Set Field [(table 2)::Last Name[GetField ((table1)::Last Name)]]

                        Select Window [Current Window]

                        Clicking the button will produce a blank record from table 2. Can you tell where I'm missing it? I think I'm close. I hope!

                        • 9. Re: Editing scripts

                          Your set field steps are not set up correctly. And you shouldn't need the function GetField for this.

                          When Setting up Set Field, there are two Specify buttons that must be clicked. To get Set Field [Table::Field ; Expression], add set field to your script and click the first button (specify target field). Select Table::Field from the list of fields. Click OK. Now click the lower specify button (calculated result) and create the expression to the right of the semicolon (;). Do not try to type in the semicolon.

                          • 10. Re: Editing scripts

                            That's where I get confused, I follow you to set field and I hit top specify button, I choose the field I need, in this case first name, click OK, the specify field table disappears and I'm back to edit script, I hit calculated result Specify button and it takes me to the specify calculation window and this is where I don't get it, on the left I've got my tables and there listed fields and on the right functions. Which function do I use? and how do I operate here, about all I've figured out is I can double click functions and they show up in the box. thats how I came up with GetField.

                            Thanks for your help.

                            • 11. Re: Editing scripts

                              Don't use a function, just double click a listed field to make it the second parameter of the set field step.

                              Also make sure that you see only one set of square brackets [] when you are done. The extra pair in your last post tells me that you were entering the calculation in the repetition box of the first Specify button which is not where this should go.

                              Now for a more basic issue. Please note that in my sample script, I don't refer to any fields in the second parameter.

                              Instead I selected the Get ( ScriptParameter ) function and passed the needed value as a script parameter. You can't use:

                              Set Field [table 2::First Name ; table1::First Name]

                              For this because this is a new record and there is no value yet entered to link this new record to any record in table1. Even though you can "keep them unique", using a name field for this is not a good idea. Names are legally changed and people make mistakes when entering a name. If you enter a name in table 1, then create several records in table 2 that link to it by that name, you can not easily change the name in table 1 without losing the link to the records in table 2. Using a serial number field avoids this issue.

                              • 12. Re: Editing scripts

                                OK, I added a full name field to both tables instead of trying to do 2 steps, 1st name & Last Name. Will this help? I still don't understand what I'm supposed to get or do when I hit the second specify button? Would it be easier to import the data from table 1 current file into table 2 and if so what's the best way to go about this.

                                I can see how a serial number or account number would be easier. Is there an easy way to assign a number to each record and does the number have to be visible on table 2?

                                • 13. Re: Editing scripts

                                  I Got it!

                                  After I went with serial numbers it all came together, I don't have to show account number field on 2nd table, however I set up a portal and chose account # for one of selected fields in portal and I can see it that way without having to print it. Which brings me to the next challenge. I would like to print these records. I need to get 2 copies of each record with both copies on the same page so I could print on perforated paper so I could easily tear in half, keeping one half and leaving 2nd half with customer I know they would fit, when I print 2 copies and then select layout choosing 2 pages per sheet it prints each copy on separate sheets. So far I haven't figured out how to do this. Any ideas?

                                  • 14. Re: Editing scripts

                                    Well not so fast, Although my button will create a new record in table 2, it doesn't create a record of the current file in table 1, it creates a record of the next sequential account number. I'm sure I'm still missing something in script. I suppose it's something behind that semicolon we talked about earlier. As of now my script in table 2 looks like this;

                                    Go to Layout [original layout]

                                    New Record /Request 

                                    Set Field [table2::Account Number]

                                    Select Window [Current Window]

                                    I really appreciate your help. Thank you!

                                    1 2 Previous Next