1 2 Previous Next 22 Replies Latest reply on Nov 12, 2012 12:57 PM by philmodjunk

    Amending a complicated looking script line...

    brian.curran

      Title

      Amending a complicated looking script line...

      Post

           Hi,
           I've been storing PDF files in containers using the Secure/External method and a freelance developer wrote an 'OpenDoc' script so that we could click on the thumbnail and open it in Adobe or any other viewer. The script is shown below...

           This was all working fine until I started to integrate GoZync, as this requires that files are embedded in Container fields for when databases are syncing over WiFi, preventing missing file references etc.

           So, my issue is how do I disentangle the following script lines so that the relevant document is opened from within the existing database file?

           Set Variable [$field; Value: "SiteDetails::" & Get ( ScriptParameter )]

            

           Set Variable [$path; Value: Let ( [file = GetField ( $field )];

            

            
           Case ( Abs ( Get ( SystemPlatform ) ) = 1 ; "filemac:" ; Abs ( Get ( SystemPlatform ) ) = 2 ; "filewin:" ) & Get ( TemporaryPath ) & Middle ( file ; Position ( file ; ":" ; 1 ; 1 ) + 1 ; Position ( file ; "¶" ; 1 ; 1 ) - Position ( file ; ":"  ; 1 ; 1)  )
           )
            
           The above makes absolutely zero sense to me so I have no chance in hell of being able to interpret it, the freelance developer has not been in touch for several months for personal reasons so I can't contact him for help either.
            
           Thanks
           Brian.

        • 1. Re: Amending a complicated looking script line...
          philmodjunk

               I don't follow what change needs to be made, but

               Case ( Abs ( Get ( SystemPlatform ) ) = 1 ; "filemac:" ; Abs ( Get ( SystemPlatform ) ) = 2 ; "filewin:" ) & Get ( TemporaryPath ) & Middle ( file ; Position ( file ; ":" ; 1 ; 1 ) + 1 ; Position ( file ; "¶" ; 1 ; 1 ) - Position ( file ; ":"  ; 1 ; 1)  )

               Can be simplified to be:

               "file:" & Get ( TemporaryPath ) & Middle ( file ; Position ( file ; ":" ; 1 ; 1 ) + 1 ; Position ( file ; "¶" ; 1 ; 1 ) - Position ( file ; ":"  ; 1 ; 1)

               No case, no need to check platforms if you use the "file:" instead of the platform specific tags.

               I'd guess that lower down in your script, you have an export field contents step that is used to export and open a copy of the file. The beauty of this method is that it does not need to be changed if the method used to insert and/or store the image is changed as it works with all options.

               The one place it would need changing, I think, is if you want to perform this script in FMGO.

          • 2. Re: Amending a complicated looking script line...
            brian.curran

                 Ah of course, the script has a whole bunch of these extra steps. Apologies for not including them, there is one for each of the 12 container fields:

                 If [$field = "SiteDetails::LocationMap"]
                 Export Field Contents [ SiteDetails::LocationMap ; "$path" ; Automatically open ]
                 End if

                 As it stands now, I'm on FM Pro 12 Adv on a Macbook and clicking the container does nothing (it should fire the Open Doc script) A colleague has the same issue on FM Pro 12 on Windows. I'm not sure what else to try next...

            • 3. Re: Amending a complicated looking script line...
              philmodjunk

                   Why not post the entire script? One thing that we can't see is how $Field gets a value and if it gets the wrong value, this won't work.

                   You can also use the DataViewer (if you have Advanced) or a show custom dialog step to check and see what data is being put in the $Path variable.

                   To post a script to the forum:

                     
              1.           You can upload a screen shot of your script by using the Upload an Image controls located just below Post A Answer.
              2.      
              3.           You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF to your clipboard for pasting here.
              4.      
              5.           If You have FileMaker Advanced, you can generate a database design report and copy the script as text from there.
              6.      
              7.           If you paste a text form of the script, you can use the Script Pretty box in the Known Bugs List database to paste a version that is single spaced and indented for a more professional and easier to read format. (Use the HTML option on the database tab panel and paste the text into the forum's HTML editor.)
              • 4. Re: Amending a complicated looking script line...
                brian.curran

                     Sorry Phil, I should have posted full information right at the start...

                     The second line that disappears off the right of the screen is shown in the second image below:

                     $field gets its value from the optional script parameter which is set as "LocationMap" for example.

                     I'll have a look at the Custom dialog next...

                     Oh, I like the number 2) option above! It drives me insane retyping script steps sometimes :D

                • 5. Re: Amending a complicated looking script line...
                  brian.curran

                        

                  Allow User Abort [ Off ]

                  Set Variable [ $field; Value:"SiteDetails::" & Get ( ScriptParameter ) ]

                  Set Variable [ $path; Value:Let ( [ file = GetField ( $field )
                            ];

                  Case ( Abs ( Get ( SystemPlatform ) ) = 1 ; "filemac:" ; Abs ( Get ( SystemPlatform ) ) = 2 ; "filewin:" ) & Get ( TemporaryPath ) & Middle ( file ; Position ( file ; ":" ; 1 ; 1 ) + 1 ; Position ( file ; "¶" ; 1;1)-Position(file;":" ;1;1) )
                            )]

                  Show Custom Dialog [ Title: $path; Default Button: “OK”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ] Pause/Resume Script [ Indefinitely ]
                  If [ $field = "SiteDetails::LocationMap" ]

                  Export Field Contents [ SiteDetails::LocationMap; “$path”; Automatically open ] Else If [ $field = "SiteDetails::SitePlan" ]

                  Export Field Contents [ SiteDetails::SitePlan; “$path”; Automatically open ] Else If [ $field = "SiteDetails::AlarmInstructions" ]

                  Export Field Contents [ SiteDetails::AlarmInstructions; “$path”; Automatically open ] Else If [ $field = "SiteDetails::ZoneList" ]

                  Export Field Contents [ SiteDetails::ZoneList; “$path”; Automatically open ] Else If [ $field = "SiteDetails::KeyHolders" ]

                  Export Field Contents [ SiteDetails::KeyHolders; “$path”; Automatically open ] Else If [ $field = "SiteDetails::GTSTagsPlan" ]

                  Export Field Contents [ SiteDetails::GTSTagsPlan; “$path”; Automatically open ] Else If [ $field = "SiteDetails::RiskAssessment" ]

                  Export Field Contents [ SiteDetails::RiskAssessment; “$path”; Automatically open ] Else If [ $field = "SiteDetails::HandSPolicy" ]

                  Export Field Contents [ SiteDetails::HandSPolicy; “$path”; Automatically open ] Else If [ $field = "SiteDetails::OtherDoc1" ]

                  Export Field Contents [ SiteDetails::OtherDoc1; “$path”; Automatically open ] Else If [ $field = "SiteDetails::OtherDoc2" ]

                  Export Field Contents [ SiteDetails::OtherDoc2; “$path”; Automatically open ] Else If [ $field = "SiteDetails::OtherDoc3" ]

                  Export Field Contents [ SiteDetails::OtherDoc3; “$path”; Automatically open ] Else If [ $field = "SiteDetails::OtherDoc4" ]

                  Export Field Contents [ SiteDetails::OtherDoc4; “$path”; Automatically open ] End If 

                        

                  • 6. Re: Amending a complicated looking script line...
                    brian.curran

                         The $path is showing as:

                    • 7. Re: Amending a complicated looking script line...
                      philmodjunk

                           The file name is missing from $Path.

                           Put this in your custom dialog:

                           $Field & " = " & GetField ( $Field )

                           and see what you get.

                           Also, what layout are you on? You should be on a layout that has "SiteDetails" selected in Show Records From in Layout Setup... (or in some cases, this can work if your layout is based on a table that is related to SiteDetails.

                      • 8. Re: Amending a complicated looking script line...
                        brian.curran

                             265 Location map.pdf is probably the file name it had orginally before being imported into the Container field...

                        • 9. Re: Amending a complicated looking script line...
                          philmodjunk

                               Yes but now to look at this calculation:

                               Let ( [file = GetField ( $field )];
                          Middle ( file ; Position ( file ; ":" ; 1 ; 1 ) + 1 ; Position ( file ; "¶" ; 1;1)-Position(file;":" ;1;1)

                               This translates into:

                               Middle ( "265 Location map.pdf" ; 0 + 1 ; 0 - 0 )

                               That returns an empty string instead of the file name.

                               This expression only works for "Store a Reference" inserts, and then only if Insert Picture was used.

                               I use this expression to extract the filename from a container field:

                               Let ( [T = GetAsText ( GetValue ( YourTable::containerField ; ValueCount ( ContainerTest::containerField ) ) ) ;
                                        L = Length ( T )];
                                        Right ( T ; L - Position ( T ; "/" ; L ; -1 ) )

                               This works for all possible combinations of insertion methods and storage options in FileMaker 12. In FileMaker 11, the same is true except that it won't return a file name if Insert Object was used to insert the file.

                               Now we can rewrite that set Variable step:

                               Set Variable [$path; Value: 
                               Let ( [file = GetField ( $field ) ;
                                       T = GetAsText ( GetValue ( file ; ValueCount ( file ) ) ) ;
                                       L = Length ( T ) ;
                                       filename = Right ( T ; L - Position ( T ; "/" ; L ; -1 ) ];
                                        "file:" & Get ( TemporaryPath ) & filename
                                      )
                               ]

                                

                          • 10. Re: Amending a complicated looking script line...
                            brian.curran

                                 I'm struggling with the Variable step, as FM is complaining that an operator is required where the closing square bracket is...

                            • 11. Re: Amending a complicated looking script line...
                              philmodjunk

                                   Don't try to add the closing square bracket, that is just the bracket provided by the script editor once you close the specify calculation dialog.

                                   But I do see a missing ) blush

                                   Set Variable [$path; Value: 
                                   Let ( [file = GetField ( $field ) ;
                                           T = GetAsText ( GetValue ( file ; ValueCount ( file ) ) ) ;
                                           L = Length ( T ) ;
                                           filename = Right ( T ; L - Position ( T ; "/" ; L ; -1 ) ) ];
                                            "file:" & Get ( TemporaryPath ) & filename
                                          )
                                   ]

                              • 12. Re: Amending a complicated looking script line...
                                brian.curran

                                     Excellent, that works great now. I did try counting all the differing brackets up but couldn't work it out :)
                                     Many thanks Phil...

                                     I may be back with a fancier script the developer did as that wasn't working last time I looked either :( From memory, it's an Import Doc script that checks to see if the container field is empty before importing the file. If it already has something saved there it renames the existing file and exports it to Dropbox.

                                • 13. Re: Amending a complicated looking script line...
                                  philmodjunk

                                       Exporting to Dropbox could be the problem. The path to the drop box folder is not the same on every computer and we don't have a get function for that path like we do temporary items, the desktop and Documents.

                                  • 14. Re: Amending a complicated looking script line...
                                    brian.curran

                                         That was definitely an issue, we have a Shared folder that each computer has in the root of the D: drive. All exported files landed in the local folder and then synced up to Dropbox.

                                         I'll have to check actually because that may or not be correct...

                                    1 2 Previous Next