11 Replies Latest reply on Mar 11, 2013 7:47 AM by Jade

    Set variable insert from URL

    PeterMontague

      Title

      Set variable insert from URL

      Post

           Is it possible to use something like insert from URL in a set variable script step? I don't want to set field. 

        • 1. Re: Set variable insert from URL
          philmodjunk

               I don't see any way to specify a variable. Looks like you have to set a field.

          • 3. Re: Set variable insert from URL
            philmodjunk

                 I wonder if this "insert..." script step has the same limitations as the other "Insert..." script steps. The other steps require that the target field must be physically present and accessible on the current layout or they fail to insert anything.

                 If so, that, sadly, makes this interesting new script step even more limited than it should be.

            • 4. Re: Set variable insert from URL
              Jade

                   Instead of 'Insert from URL', use a webviewer and 'GetLayoutObjectAttribute'.  I think you can use a variable then: e.g:

                   Set Variable[$variable_name ; Value: GetLayoutObjectAttribute( WebViewer_name ; "content" )]

              • 5. Re: Set variable insert from URL
                Jade
                     

                I wonder if this "insert..." script step has the same limitations as the other "Insert..." script steps.

                Yes, it appears that the target field must be on the layout.

                • 6. Re: Set variable insert from URL
                  PeterMontague

                       I named my webviewer "Parent".

                       I referred to it in my function like this GetLayoutObjectAttribute( Parent ; "content"). But it is giving me the message that the specified field could not be found. I named the webviewer on the position tab of the inspector. Is that the right thing to do?

                        

                  • 7. Re: Set variable insert from URL
                    Jade

                         GetLayoutObjectAttribute( "Parent" ; "content" )

                         Text literals require quotation marks.

                          

                         P.S. I haven't hit the 64k boundary yet on iOS but it may happen.  Please let me know how this works out.  Thanks!

                    • 8. Re: Set variable insert from URL
                      PeterMontague
                           

                      GetLayoutObjectAttribute( "Parent" ; "content" )

                      This returns the source code in the data viewer. I used this set variable script step. 

                      Set Variable[ $Parent_source_code; Value:GetLayoutObjectAttribute ( "Parent" ; "Content" ) ]

                      The function returns the source code. But when I look up the $Parent_source_code in the data viewer it returns a blank. What am I doing wrong?

                      • 9. Re: Set variable insert from URL
                        Jade

                             ❹

                             You may have to Pause for a second or two to give the webviewer time to fully load the webpage before you set the variable:

                        Pause/Resume Script[ Duration (seconds): 1]

                             Set Variable[ $Parent_source_code ; Value: GetLayoutObjectAttribute( "Parent" ; "content" ) ]

                             ❷

                             … or you might need to use a global variable ($$Parent_source_code) instead of the local ($Parent_source_code) if you are viewing the the variable content with the data viewer after your script has terminated.  

                              

                                                                                                                             
                                                 
                                            
                                                 
                        A local variable can only be used in script steps in the currently executing script. The value in a local variable is cleared when the script exits. Local variables are prefixed with $.
                                            
                                                                                                                             
                                                 
                         •
                                            
                                                 
                        A global variable can be used in a calculation or script anywhere in a file, for example, other scripts or file paths. The value of a global variable is not cleared until the file is closed. Prefix global variables with $$.
                                            

                             (You can temporarily put a Show Custom Dialog immediately after the 'Set Variable' scriptstep to display the contents of $Parent_source_code to be sure that the content is correct.  Alternatively, pause the script  immediately after the 'Set Variable' scriptstep and use the Data Viewer to view the contents there.)

                             ❸

                             …and the "content" attribute name should be all lower case.  (I don't know if this is really an issue but you have written it as "Content" in your last post.)

                        • 10. Re: Set variable insert from URL
                          PeterMontague
                               

                          Pause/Resume Script[ Duration (seconds): 1]

                          This worked well for me. So did the $$ prefix. The source code is very long. Sometimes the script gets it to download but I'm not able to parse out the text I want. But if I repeat the script it works fine. I think it just needs a longer pause to work every time. 

                          I tried this out on FM Go. The custom dialog step helped here. I can see that the source code was only partially downloaded into the variable here. I thought that maybe the script needed a really long pause. So I upped it to ten seconds. But it didn't make a difference. The part that I wanted to parse out was not available in the variable in FM Go.

                          So it looks like it is not going to work.

                                

                          • 11. Re: Set variable insert from URL
                            Jade

                                 Thank you for the feedback, Peter.  

                                 The iPad has a much slower processor so a pause of 30 to 60 seconds in FM Go might be worth a try if you can tolerate such a long delay here.  

                                 So I suppose there is no other URL that can return the sub-set of source code that you need?