1 2 Previous Next 16 Replies Latest reply on Jun 3, 2014 10:19 AM by philmodjunk

    insert text and Loop

    jhc

      Title

      insert text and Loop

      Post

           having trouble with creating a KML file. I'm at the point now where everything is working except for the header which is inserted using an "Insert Text"

           That happens before the loop. Everything inside the loop gets executed but nothing before the loop. Anyone have any ideas as to why that is? 

           my fmp file is here: ftp://ftp.geobc.gov.bc.ca/publish/Regional/Surrey/tmp_dikeForms/

            

           thx in advance

        • 1. Re: insert text and Loop
          philmodjunk

               What is a "KML" file?

               Insert text, like copy, paste and all other script steps that start with the word "insert", will not work if the field receiving the inserted data is not present on the current layout and accessible when in Browse mode at the time the script step executes.

               This is the main reason why I avoid those steps and use Set Field whenever possible. And set field can be used to insert text before, after, in the middle of existing text in the field or even at the current position of the cursor in that field.

          • 2. Re: insert text and Loop
            jhc

                 the FMP form I placed on the FTP site does have the field receiving the inserted data on there and it's visible to the user.

                 I'll give it a try but this code was copied from another app that works. I didn't write it - someone else did. If it works for him I haven't figured out why it won't work for me; especially when - if you open up my form, you'll see that I've stripped all the complexity out of it. I'm actually troubleshooting a bigger more complicated form. But  I just wanted to make this one thing work before moving on to the next crisis. So far - still stuck. 

                 I'll try "set field" and see if that works but if Insert doesn't work reliably then maybe Filemaker should consider fixing it or removing it from the list of available functions. 

            • 3. Re: insert text and Loop
              jhc

                   is there a way for FMP to ignore the quotations? I'm trying to do the SetVariable but I need it to look like this: 

                   
                        <?xml version="1.0" encoding="utf-8"?>
                         
                        <Document>
                   
                        <Folder>
                   and it's bombing because of the quotations. Is there some special character that tells FMP to ignore the quotes?
              • 4. Re: insert text and Loop
                philmodjunk

                     put a \ immediately in front of each double quote character. Then FileMaker will treat the quote as a character and not the marker for the end of the quoted text.

                     this code was copied from another app that works. I didn't write it - someone else did. If it works for him I haven't figured out why it won't work for me;

                     Scripts in FileMaker are very "layout sensitivie". if the current layout isn't designed the same, your copied script may not work.

                     And since this field is in the header, you might check to see if it needs to be a field with global storage. If you place a field in the header of a list view layout and it is not a global field, In Browse mode, it displays data from which ever record is current. If you change to a different current record, the value in the field could easily change. So your script may have worked just fine, but modified the value of this field in a different record than you expected and thus it appears to fail.

                • 5. Re: insert text and Loop
                  jhc

                       unfortunatley that still didn't work. The part that it copies content from one field into the accumulate field works. But the header (the section of my script before the loop) still doesn't work. I even changed it to just write "blah blah blah" instead of the header but nope. It's like it doesn't exist.

                       If you are unable to access the FTP site (it's public so it's should be open) then here is the script: 

                       Export Records to a kml file
                       Clear [ KMLmakerTest::AccumulateKMLOut ]
                       [ Select ]
                       Go to Record/Request/Page
                       [ First ]
                       # Set up the name for the file and the folder. Both have date and time, but need to be formatted differently.
                       Set Variable [ $Filename; Value:"KMLmakerTest" ]
                       Set Variable [ $Counter; Value:1 ]
                       Set Variable [ $FileCounter ; Value:0 ]
                       #
                       Put in the header for the kml file.
                       // Insert Text [ KMLmakerTest::AccumulateKMLOut; “<?xml version="1.0" encoding="utf-8"?>
                       net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
                       <Document>
                       <Folder>
                       <name>” ]
                       [ Select ]
                       Set Variable [ $kmlHeader ; Value:"<?xml version=\"1.0\" encoding=\"utf-8\"?>
                       <kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\" xmlns:kml=\"http://www.opengis.
                       net/kml/2.2\" xmlns:atom=\"http://www.w3.org/2005/Atom\">
                       <Document>
                       <Folder>
                       <name>" ]
                       Set Field [ KMLmakerTest::AccumulateKMLOut ; "blah blah blah" ]
                       // Insert Current Date [ <Table Missing> ]
                       // Insert Text [ <Table Missing>; “__” ]
                       // Insert Current Time [ <Table Missing> ]
                       Insert Text [ KMLmakerTest::AccumulateKMLOut ; “</name>” ]
                       Go to Record/Request/Page
                       [ First ]
                       Loop
                       // Copy [ KMLmakerTest::KMLOutput ]
                       [ Select ]
                       Set Variable [ $kmlOut ; Value:KMLmakerTest::KMLOutput ]
                       # Test to see if output will exceed the Go limit of 64,000 characters
                       If [ /*(Length (KMLmakerTest::KMLOutput ) + Length (KMLmakerTest::AccumulateKMLOut )) > 63900*/ ]
                       Insert Text [ KMLmakerTest::AccumulateKMLOut ; “</Folder>
                       </Document>
                       # >63900
                       </kml>” ]
                       Set Variable [ $Filename2; Value:$FileCounter &"_"& $Filename ]
                       Export Field Contents [ KMLmakerTest::AccumulateKMLOut ; “$Filename2” ]
                       Clear [ KMLmakerTest::AccumulateKMLOut ]
                       [ Select ]
                       Insert Text [ KMLmakerTest::AccumulateKMLOut ; “<?xml version="1.0" encoding="utf-8"?>
                       <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.
                       opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
                       <Document>
                       <Folder>
                       <name>” ]
                       [ Select ]
                       May 21, 2014 11:44:55 KMLmakerTest Copy part 2.fmp12 - Export Records to a kml file -1-
                       Export Records to a kml file
                       // Insert Current Date [ <Table Missing> ]
                       // Insert Text [ <Table Missing>; “__” ]
                       // Insert Current Time [ <Table Missing> ]
                       Insert Text [ KMLmakerTest::AccumulateKMLOut ; “</name>” ]
                       Set Variable [ $FileCounter ; Value:$FileCounter + 1 ]
                       End If
                       # Test to see if number of Placemarks is greater than PDF Maps limit of 200
                       If [ $Counter > 200 * $FileCounter + 200 ]
                       Insert Text [ KMLmakerTest::AccumulateKMLOut ; “</Folder>
                       </Document>
                       # >200
                       </kml>” ]
                       Set Variable [ $Filename2; Value:$FileCounter &"_"& $Filename ]
                       Export Field Contents [ KMLmakerTest::AccumulateKMLOut ; “$Filename2” ]
                       Clear [ KMLmakerTest::AccumulateKMLOut ]
                       [ Select ]
                       Insert Text [ KMLmakerTest::AccumulateKMLOut ; “<?xml version="1.0" encoding="utf-8"?>
                       <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.
                       opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
                       <Document>
                       <Folder>
                       <name>” ]
                       [ Select ]
                       // Insert Current Date [ <Table Missing> ]
                       // Insert Text [ <Table Missing>; “__” ]
                       // Insert Current Time [ <Table Missing> ]
                       Insert Text [ KMLmakerTest::AccumulateKMLOut ; “</name>” ]
                       Set Variable [ $FileCounter ; Value:$FileCounter + 1 ]
                       End If
                       // Paste [ KMLmakerTest::AccumulateKMLOut ]
                       Set Field [ KMLmakerTest::AccumulateKMLOut ; KMLmakerTest::AccumulateKMLOut & $kmlOut ]
                       Insert Text [ KMLmakerTest::AccumulateKMLOut ; “
                       ” ]
                       Set Variable [ $Counter ; Value:$Counter + 1 ]
                       Go to Record/Request/Page
                       [ Next; Exit after last ]
                       End Loop
                       #Put in the footer for the kml file.
                       Set Variable [ $Filename2; Value:$FileCounter &"_"& $Filename ]
                       Insert Text [ KMLmakerTest::AccumulateKMLOut ; “</Folder>
                       </Document>
                       </kml>” ]
                       Export Field Contents [ KMLmakerTest::AccumulateKMLOut ; “$Filename” ; Create email ]
                       // Clear [ KMLmakerTest::AccumulateKMLOut ]
                       [ Select ]
                       May 21, 2014 11:44:55 KMLmakerTest Copy part 2.fmp12 - Export Records to a kml file -2-
                  • 6. Re: insert text and Loop
                    philmodjunk

                         I finally downloaded a copy of your file. Are you referring to the script named "KML Maker2"?

                         And when I checked the AccumulateKMLOut field on the layout, I found that it does not allow Browse Mode access.

                         This will prevent the Clear and the Insert script steps from modifying this field.

                         And I also note that you have two different fields receiving data in this script AccumulateKMLOut and also KMLOutput.

                         And note the /* comment brackets */ That enclose the following expression inside one of your If script steps:

                         /*Length ( KMLmakerTest::KMLOutput ) + Length ( KMLmakerTest::AccumulateKMLOut ) > 63900*/

                         Those bracket mean that the script steps enclosed in this If block are never executed as the "commented out" expression never evaluates to a value of True.

                         And when I run my own script:

                         Set Field [KMLmakerTest::AccumulateKMLOut ; "blah blah blah" ]

                         it assigns the text "blah blah blah" to the field as expected as long as I do not have an empty found set at the time that I run this script. Since I used set field for this test, it assigns this text to the field even if browse mode access to the field is not permitted on the current layout.

                    • 7. Re: insert text and Loop
                      jhc

                           no, that was my older script which I bailed on and ended up importing my colleague's script called "Export records to a kml file" and then linked the proper fields into the script. 

                           I tried opening up that field "AccumulateKMLOut" so that it is accessible in browse and find modes. I also tried removing the comments around the IF statement. But it is still not performing the steps before the "Loop" 

                            

                      • 8. Re: insert text and Loop
                        philmodjunk

                             So I ran the following test:

                             I created a new record (There were no records in the table)

                             I then ran the "Export Records to a kml file" from Manage | Scripts

                             The result is shown in the uploaded screen shot.

                        • 9. Re: insert text and Loop
                          jhc

                               that's what I want to see... unfortunately i don't get anything before <Placemark>

                               did u change anything? 

                          • 10. Re: insert text and Loop
                            philmodjunk

                                 The only change that I made was to allow browse mode access to the field at the bottom of the layout and then, as I described earlier, I created a new blank record.

                                 I did first put a pause right after the first insert text script as a test of the idea that your script might be inserting the data but then deleting or overwriting it, but when I saw the expected data and didn't see any steps that would do that, I removed that step and ran the script again--producing the results shown in the screen shot.

                            • 11. Re: insert text and Loop
                              jhc

                                   I did the "allow browse" thing. I tried commenting out the entire Loop. I also got rid of all the disabled comments after my last episode where they were being read for some reason. 

                                   So without Loop the header gets written. But when I reinstate the loop, those first few "SetField"/"InsertText" statements either don't happen or their results get overwritten. So there's something going on inside that loop that I don't understand that is obliterating the text that goes in beforehand. 

                              • 12. Re: insert text and Loop
                                philmodjunk

                                     This doesn't sound like the same script that I was testing. Note that I did not try testing this script by clicking a button on your layout, I ran it from Manage | Scripts so it's possible that if you are performing the script by clicking a button that you aren't performing the same script. Or maybe the copy that you uploaded is no longer the same as the file that you are testing now.

                                     Both Insert and Set field can overwrite existing data instead of appending data to that already present in the field. It depends on how you use them.

                                     Set field needs to be set up this way to append text:

                                     Set Field [ YourTable::field ; YourTable::field & //expression to add new text goes here ]

                                     With Insert steps, you need to make sure that both the field on the layout is not set to "select entire contents on entry" and that you don't select the "select entire contents" option at the bottom of the script editor for that Insert step or it will overwrite existing data in the field.

                                • 13. Re: insert text and Loop
                                  jhc

                                       yes I was using the buttons to run the script. I've made a lot of edits to it based on suggestions here so it's not the exact same script as posted here. But even the one posted here I'm fairly certain I got rid of all the "select" statements that would have made the Insert Text overwrite everything. I'll try removing all Insert Text statements, replace them all with the "set field" and try again. 

                                        

                                  • 14. Re: insert text and Loop
                                    philmodjunk

                                         That that was not the issue in the copy that you uploaded. It ran apparently correctly without the need for any additional modifications.

                                    1 2 Previous Next