5 Replies Latest reply on Mar 8, 2013 11:56 AM by Jade

    Can a script get a value from the web?  (a currency exchange rate)

    R12GS

      Title

      Can a script get a value from the web?  (a currency exchange rate)

      Post

           I need to record a currency exchange rate every day and then use that rate in the script.

            

           I want a server script to get this exchange rate ("1.3010") from this page, every day and save it in a field.

           http://www.ecb.int/stats/exchange/eurofxref/html/eurofxref-graph-usd.en.html

           I don't know anything about RSS feeds, but the very first 6 characters is what I want from this RSS feed ("1.3010"

      http://www.ecb.europa.eu/rss/fxref-usd.html

            

           Basically I want the Filemaker script to surf the web for me and get a number off a website at 6AM.  Is this even possible?

        • 1. Re: Can a script get a value from the web?  (a currency exchange rate)
          Jade

               Yes.  If you are using FMP 12, see the help text for the scriptstep 'Insert from URL'.  

               This retrieves the webpage content (HTML) from a specified web address (URL) and stores it in a FMP text field.  From there, you can use the Position()  and Middle() functions in your script to locate and extract the exchange rate from the text field.

               You may be able to use the 'Install OnTimer Script' to run the script at 6AM as long as  the window running the script is left open.  If you have FMS, you can probably schedule it.

               This is a script example:

                

          Insert from URL [ Your_Table::ECB; "http://www.ecb.europa.eu/rss/fxref-usd.html" ]

          [ Select; No dialog ]

          Pause/Resume Script [ Duration (seconds): 1 ]
          Set Field [ Your_Table::Exchange Rate; Middle( Your_Table::ECB; Position ( Your_table::ECB ; "<title xml:lang=\"en\">" ; 1 ; 1 ) + 21 ; 6) ] 

                

          • 2. Re: Can a script get a value from the web?  (a currency exchange rate)
            philmodjunk

                 If you are not using FMP 12, there are ways to "scrape" data from a web viewer using the GetLayoutObjectAttribute function.

            • 3. Re: Can a script get a value from the web?  (a currency exchange rate)
              R12GS

                   Thanks Jade, those FM12 steps are great -  thanks for providing such a complete answer.   That's programming that I can work from! , except...-----  we have FM11 (and FMS11) dangit!

                   Thanks for the tip Phil, i'll be studying this page about GetLayoutObjectAttribute function

                    http://help.filemaker.com/app/answers/detail/a_id/6146/~/using-the-getlayoutobjectattribute-function

                    

              • 4. Re: Can a script get a value from the web?  (a currency exchange rate)
                philmodjunk

                     What you have to do is add a web viewer, give it an object name (so that getLayoutObjectAttribute can reference it) and then you use the function's "content" option to pull the content of the web viewer into a text field.

                     Then the fun begins....

                     Buried somewhere in the mass of HTML tagged text returned by this function, you will find the data you want. The challenge, once you are successfully loading a text field with this content, is to use fileMaker's text functions (or custom text parsing functions if you have Filemaker Advanced) to find and extract the needed data.

                     And if the web developers redesign the web page, you have to update your scraping methods accordingly...

                • 5. Re: Can a script get a value from the web?  (a currency exchange rate)
                  Jade
                       

                  Buried somewhere in the mass of HTML tagged text returned by this function, you will find the data you want. The challenge, once you are successfully loading a text field with this content, is to use fileMaker's text functions (or custom text parsing functions if you have Filemaker Advanced) to find and extract the needed data.

                       Use:

                  Set Field [ Your_Table::Exchange Rate; Middle( Your_Table::ECB; Position ( Your_table::ECB ; "<title xml:lang=\"en\">" ; 1 ; 1 ) + 21 ; 6) ]

                       It works for now.  

                       To future-proof your script somewhat, replace "<title xml:lang=\"en\">" by a global text field that contains: <title xml:lang=\"en\">

                  Also replace the value 21 (which is the offset from the begining of the search text) by a global number field.