7 Replies Latest reply on Feb 1, 2014 10:00 AM by philmodjunk

    Moving calc definition from direct Let statement, to string in a field?

      Title

      Moving calc definition from direct Let statement, to string in a field?

      Post


           I have a web viewer that I had been defining w/ calculation.  It involved a let statement and a bunch of CSS, HTML and Javascript.  However, I want to use this web viewer in a number of locations, so I would like to put that string for the calculation definition into a field in a table, so that I can make updates to them all at one time.

           But, my initial attempts to do so aren't working.  I just copied the calculation text from the WV to the text field (made one record in the other table).  I made a text field in another table (unrelated), used an ESQL statement to grab it.  But my web viewer is blank.

           I tried using "Quote ( ExecuteSQL (...) ) ", didn't work.   I tried "Let ( a=1; Quote ( ExecuteSQL (...) ) )" but that didn't work. 

           Any ideas?

           - J

        • 1. Re: Moving calc definition from direct Let statement, to string in a field?
          philmodjunk

               When you put the URL into a text field, the contents of that field are not being evaluated. If you have text such as:

               http://forums.filemaker.com/comment/269272

               in your text field, there's no expression to evaluate and you can set up the web viewer to directly reference the URL entered in the text field.

               But you have an expression entered in the text field.

               So you'd need to set up the calculation in the web viewer as:

               Evaluate ( textfieldRefGoesHere )

          • 2. Re: Moving calc definition from direct Let statement, to string in a field?

                 Thanks, Phil, that appears to have done the trick.  Haven't ever used Evaluate() before...

                 Maybe it's just JavaScript, but are there any drawbacks to Evaluate()?  I am only using an internal field, which is only settable from a single utility layout, as input, so I would think it is fairly harmless.

                 --  J

            • 3. Re: Moving calc definition from direct Let statement, to string in a field?
              philmodjunk

                   Evaluate is a very useful FileMaker Function. It's not JavaScript. It's documented in FileMaker help.

              • 4. Re: Moving calc definition from direct Let statement, to string in a field?

                     Hrmm....I swear it was working when I first responded, but now I can't get the Evaluate () to yield any results from the text in my field.  I imagine that it is due to the need to escape some quotes somewhere along the line.  My field definition has a somewhat complex Let() statement in it with variables, strings, variables concatenated with strings, etc. 

                     Any hints on rules to using Evaluate()?  When I look at the return values in the data viewer it is readable text that is valid in the calculation window, but isn't liked by Evaluate.  If I take the output that I am handing to Evaluate and paste it directly into the web viewer definition, it works fine.

                     I have tried both of these as the definition of my webviewer.  (The GFN and GTN functions are just ESQL-robustifying functions that just return the Field name or Table name, respectively)

                     

                          Evaluate (
                              ExecuteSQL ( "SELECT " & GFN ( Comment_Support::WebViewer_Single ) & " FROM " & GTN ( Comment_Support::WebViewer_Single ) ; "" ; "")

                          )

                     

                          Evaluate (
                          Quote (
                              ExecuteSQL ( "SELECT " & GFN ( Comment_Support::WebViewer_Single ) & " FROM " & GTN ( Comment_Support::WebViewer_Single ) ; "" ; "")
                          )
                          )

                      

                     This field definition is OK and I see the result in the web viewer (using the non-Quote() version of Evaluate):

                     

                          Let ( [
                          _var = "Ba a a"
                          ];

                          "data:text/html,   
                          <html>
                          <Body>
                          <h1>" & _var & " </h1>
                          </body></html>"
                          )
                           

                     But then this one fails (using either version, Quote() or not, of Evaluate):

                     

                          Let ( [
                          _var1 = "Ba a a La La Tra Tra " ;
                          _var2 = "abc"
                          ];

                          "data:text/html,   
                          <html>
                          <Body>
                          <h1>" & _var1 & " </h1>
                          </body></html>"
                          )

                     Frustrating.  Any pointers on special escaping considerations to make it evaluate correctly?

                     Thanks, -J

                • 5. Re: Moving calc definition from direct Let statement, to string in a field?
                  philmodjunk

                       Is the text that you are quoting in the second case the actual text returned by Evaluate or the text that should be returned in order for the web viewer to work?

                       I really don't see any reason for using ExecuteSQL here, that seems a needless complication. But then I have no idea what the GTN or GFN functions are defined to do here either.

                  • 6. Re: Moving calc definition from direct Let statement, to string in a field?

                         Long time away, but finally getting back to this a bit:  the text in FieldA is to become the calculation string used to define web viewerA.  So my definition of web viewerA would be a calculation that simply is:

                             table::FieldA

                         That way I can point multiple web viewers on different layouts to one place and update them all at the same time.  That's the whole issue here; I have multiple web viewers that are all defined the same, but I don't want to have to go and copy/paste the calculation text in each place every time I have a change I want to make.

                         I surmise that part of the problem is that the web viewer has references and calculations it makes to other fields, concatenating things, etc.  Some web viewerA = FieldA = Let(var1 = xyz; ) & FieldB & FieldC & "stuff" & FieldD + FieldE...

                         ESQL was used to eliminate the need for a relation.

                         -- J

                    • 7. Re: Moving calc definition from direct Let statement, to string in a field?
                      philmodjunk

                           I've been re-reading this for a while and am not seeing any obvious syntax issues. The problem can be with how a table or field is named unless your GTN and GFN functions are correctly quoting them. (A field or table name that starts with _ or that is a SQL keyword will produce a syntax error in the SQL query unless correctly enclosed in double quotes.

                           I suspect that this is not the issue given your reported results. The non-quoted ESQL example looks correct to me given that you want to evaluate the text stored in the field queried via ESQL. But given that there is no Join or WHERE clause in your ESQL, You should be getting the results of multiple records in the table jammed together with no separation. If you have 5 records in CommentSupport, You should be getting: WebViewer_SingleWebViewer_SingleWebViewer_SingleWebViewer_SingleWebViewer_Single only with the contents of this field where I have listed the name. That seems unlikely to work.

                           A simpler way that you might use to do this is to use a script to load the WebViewer HTML/Java text into a global field and then it can be accessible from any record and layout in your file.