1 2 3 Previous Next 40 Replies Latest reply on Sep 24, 2016 10:37 AM by jsanders

    Creative uses for snapshot links

    Extensitech

      Note: I tried posting this as an "idea", but it seems I'm doing it wrong. If I'm doing it wrong now, and just created a duplicate thread, I apologize and request assistance.

       

      I've been doing some creative things with snapshot links, and though I'd share, to see what refinements or other creative ideas you FM geniuses might have. Plus, I thought it might be fun on this forum to discuss something fun and new, rather than just problems to be solved. :-)

       

      In the future, I might blog about this, but it's a topic for a pretty narrow audience anyway. For now, I'd like to share my raw findings and see if anyone here would like to "riff" on them.

       

      So...

       

      The original thing that caught my attention was that snapshot links include sort information. As is periodically noted, we don't currently have a way in FM scripts to change a sort without creating a Sort script step for any combination/permutation of sort criteria we want. So I started wondering whether I can create a snapshot link, alter the sort order, then open that snapshot link with the new sort order. That works (I'll outline some techniques and gotchas in a minute) but there are other things in the .fmpsl file, as well. Go ahead and save a snapshot link (you may first want to find a few records and sort them, just to give your snapshot some decent content) then open that up with a text editor, and you can follow along.


      Path to the file - this is the fmnet address, and if the file is local it's both the fmnet address of your machine and the path to the file on disk

      The count of the rows - the found count

      The base table id - this is, frankly, a bit mysterious to me, although that's not an issue for me currently. It doesn't seem to correspond to the number you get using the TableIDs function.

      "CDATA" - this is a ranged list of record id's. ( " get ( recordID ) " ) (For various reasons, I'd like to be able to create a fmpsl from scratch, and this is the item that seems to make it easiest to just have FM create one and then modify it. I can write a custom function that'll create this cdata, but it won't perform as fast as (or at least, not any faster than) just creating an fmpsl and reading it.)

      LayoutID - you can get this with the layoutIDs function. (Of course, you'll also use the layoutNames function to find which id in the list goes with which layout.)

      View Type - list, form, table

      The id of the selected row - get ( recordID )

      Status of the toolbar - pretty obvious

      Mode - browse, find, preview... haven't tested if this works for layout, for fa users

      Sort parameters - finally, the sort parameters. I won't break these down further here, since you can save a few fmpsl files and get the gist pretty quickly. I will point out that, for the field table ID and the field ID, you might consider using executeSQL as described here: http://www.databuzz.com.au/using-executesql-to-query-the-virtual-schemasystem-tables/ . I only found out about this recently (don't know how I missed it) but it rocks!

       

      (Although this worked out not to be useful for my purposes, I should also note that anything below and outside the <FPSL> tag will be ignored by FM when the file is opened. If you end up wanting to keep a bunch of these, for example, in a temp folder, you could use that to stash some extra details, like fronted panels and such.)

       

      OK, so first off, how could we create, read and update these files? At first, I went with 360Works ScriptMaster (the swiss army knife), but thanks to some help from Brian Sanchez at aAce, I now have a way to work with the text file without a plugin.

       

      To create it, I use the Save Records as Snapshot Link script step, and save the the temporaryPath

      To read it, put the .fmpsl into a container field (it can be a global), and then calculate Base64Decode (  Base64Encode ( ContainerField )  )

      To update it, I parse and alter the text (I'm not going to go through the details of that unless asked, since we all have our own parsing methods)

       

      Now I've got an updated snapshot link as text, and I need to open it. This turned out to be trickier than expected. If you try using export field contents, you get the wrong format. The formats you get from exporting a single record and single field get you closer, but they mess with the line feeds. Either of these cause FM to throw error saying that FM didn't create the file (busted!).

       

      However, if you use a virtual list, and export a record for each "paragraph" (other than those generated by the return-separated cdata, there aren't a lot, although cdata could require plenty), and then export with the utf-8 format, you'll get a usable .fmpsl, which you can then open.

       

      So, now we can create a snapshot link, bring the text from that link into FM and manipulate it, then create a new, updated snapshot link that we can open. What now?

       

      Well, first, an important caveats:

       

      First, a snapshot link always opens in a new window. If anyone finds a way around this, please let me know post haste!

       

      Also, if you run a script to create and open the updated snapshot link, the snapshot link will open after your script(s) are completely finished. This means that, for example, if you want the newly opened window to replace the user's existing window, you'll need that part to run as a new script after the snapshot opens. One way is simply to put some parameters in a global field that are fetched by a script trigger when the new window opens.

       

      So, finally, what can we do with this?

       

      I'm sure others can add to this list, but here are some areas where I'm using it and/or experimenting:

       

      Dynamic sorting - this was, as mentioned, my initial reasoning for going down this path. The thing about opening after scripts are finished is a bit of a headache, but I think (given that we use parameter-driven, layout-independent scripts for just about everything) that I can work around this by caching my script parameters in a global, ending the script, letting the snapshot open and then having the script trigger find the rest of the parameters and continue.

       

      Back and Forward Navigation - I have this working, since I don't want users moving back and forward while another script is running, anyway. Whenever I have a found set I want to cache in the back (or forward) history, I create a .fmpsl to get that pesky cdata and stuff, then capture the text. If the user does anything that would alter the file, like switching to a list layout of the same table, or omitting a record, deleting a record, creating a new record, etc., I update the stored text. If they hit back, I can export that new .fmpsl and open it. I originally had this working with ScriptMaster, but the reading and writing to the file were prohibitively slowing things down. It's pretty smooth, now.

       

      Passing found sets between TO's and Files - I'm still ramping this one up, but in theory, I could pass a found set, sort order, etc. from one interface file to another interface file. My reasons for wanting this are probably a bit arcane, but in brief, my big hairy goal right now is to separate customizations from standard modules, so if I can have, for instance, Contacts in our base interface file and Contacts in a custom interface file, and move smoothly between them, that'll be a big step.

       

      So...

       

      Anyone else have any ideas about this? Things I've overlooked? (I'm sure there's plenty!) Other possible uses?

       

      Chris Cain

      Extensitech

        • 1. Re: Creative uses for snapshot links
          beverly

          noble endeavor, Chris! the .fpsl is XML, and FM can eat XML for breakfast. you could use XSLT to make the import/export work differently. this may be used to achieve your goal of passing found sets (and sorting).

           

          beverly

          • 2. Re: Creative uses for snapshot links
            Benjamin Fehr

            great concept!

            I try to imagine where this would lead if we could write this snapshot-information in a field or as a Var instead of a save-as task.

            A new FM-Function then should allow a "go-to" task with the snapshot coordinates.

             

            <?xml version="1.0" encoding="UTF-8"?>

            <FPSL><UIState><UniversalPathList>fmnet:/192.168.0.50/MySolution.fmp12&#10;filemac:/Macintosh HD/Users/…/MySolution.fmp12</UniversalPathList><Rows type="nativeIDList" rowCount="1" baseTableId="130"><![CDATA[775

            ]]></Rows><Layout id="593"></Layout><View type="form"></View><SelectedRow type="nativeID" id="775"></SelectedRow><StatusToolbar visible="True"></StatusToolbar><Mode value="browseMode"></Mode><SortList Maintain="True" value="False"></SortList></UIState></FPSL>

             

            Further, I would need coordinates for Object-Name to save position of current Slide-Element

            • 3. Re: Creative uses for snapshot links
              Extensitech

              True.

               

              XSLT isn't a tool I've taken out of the toolbox in a while, though. I'd love to see what someone could do with that!

               

              I've found that the custom functions I use for passing multiple script parameters already made most of the data parsing pretty easy.

               

              Chris Cain

              Extensitech

              • 4. Re: Creative uses for snapshot links
                Extensitech

                Yeah, it would be nice to be able to "open" a .fmpsl from a variable or field (especially in the current window).

                 

                Barring that, though, I'm just ending up saving an .fmpsl initially to get the cdata, and then export/open to go to one. The in-between edits I can do in FM.

                 

                If I could come up with a way to create the cdata efficiently, I could eliminate the first save and just "roll my own". I can do it with custom functions and such, but it takes longer than just saving a .fmpsl and reading it. Any ideas?

                 

                Chris Cain

                Extensitech

                • 5. Re: Creative uses for snapshot links
                  beverly

                  That depends on really what you hope to do with it, Chris. Take a snapshot, go to another layout, apply the find/sort? If so, you take another snapshot of the new layout and apply the bits needed for it and put INTO the previous snapshot via XSLT (reading both fpsl and spitting out new one). Or do you intend to allow the user to specify find criteria (in globals, for example) and then apply them to the first snapshot (via XSLT) and then open it?

                   

                  I'm just not sure the advantage of this, but then I don't know exactly what you had in mind or how others might wish to apply this method.

                   

                  beverly

                   

                  On Jun 14, 2015, at 2:20 PM, Extensitech <noreply@filemaker.com> wrote

                   

                   

                  Creative uses for snapshot links

                  reply from Extensitech in Discussions - View the full discussion

                  True.

                   

                  XSLT isn't a tool I've taken out of the toolbox in a while, though. I'd love to see what someone could do with that!

                   

                  I've found that the custom functions I use for passing multiple script parameters already made most of the data parsing pretty easy.

                   

                  Chris Cain

                  Extensitech

                  Reply to this message by replying to this email, or go to the message on FileMaker Community

                  Start a new discussion in Discussions by email or at FileMaker Community

                  Following Discussions in these streams: Connections Stream

                  Following Creative uses for snapshot links in these streams: Inbox

                  Manage your email preferences

                   

                  FileMaker Developer Conference 2015 • Las Vegas, Nevada • July 20-23 • www.filemaker.com/devcon

                   

                  • 6. Re: Creative uses for snapshot links
                    Extensitech

                    Take a snapshot, go to another layout, apply the find/sort? If so, you take another snapshot of the new layout and apply the bits needed for it and put INTO the previous snapshot via XSLT (reading both fpsl and spitting out new one). Or do you intend to allow the user to specify find criteria (in globals, for example) and then apply them to the first snapshot (via XSLT) and then open it?

                    I'm not sure what you mean about search criteria, since the .fmpsl doesn't take find criteria, but as I've said, I'm open to new ideas and uses.

                     

                    That depends on really what you hope to do with it, Chris.

                     

                    Basically, I'm looking for, and essentially have, CRUD control of the .fmpsl. I can Create it, Read it, Update it and, of course, Delete it.

                     

                    So, in the three use cases I began with (in the original post), I can

                     

                    1. use this method to sort records without hard coding

                    2. use this method to cache and restore a user's previous window, including the sort order, view, mode, etc. There are other methods to do this (up to now, I've been caching and hiding windows), but I think this is cleaner than most methods I've seen.

                    3. I can alter a cached view and pass it to a different interface file. So, for example, I can pass a found set and sort order from interface file A to interface file B without trying to re-create the user's finds, omits, sorts, etc., or doing a potentially many-request find to get all the same keys.

                     

                    I could imagine XSLT having a role in importing, modifying and exporting the .fmpsl, although I'm not sure the specifics of how that would work. Is that what you had in mind when you suggested it? I'm not sure how I'd use it to improve what I'm doing already but, well, you're the one who brought it up, Beverly.

                     

                    Chris Cain

                    Extensitech

                    • 7. Re: Creative uses for snapshot links
                      Benjamin Fehr

                      I started a concept with a custom function to set a Script-Variable with the current $$coordinates.

                      Maybe this works out for your ideas.

                       

                      I use "|" (pipes) as separators between different attributes.

                      To give a example:

                      "|" & Get(LayoutName) & "|" & current ObjectName & "|" … & "|"

                       

                      Once more it's the Brian Dunning GetBetween cf to extract then:

                      FileMaker Custom Function:getbetween(text, starttext, stoptext,occurrence)

                       

                      text= $$coordinates

                      starttext/stoptext= "|"

                      occurrence

                      1= LayoutName =>$Layout

                      2= ObjectName => $Object

                       

                      Your script could be:

                           gotoLayout ($Layout)

                           gotoObject($Object)

                      • 8. Re: Creative uses for snapshot links
                        Extensitech

                        I'm sorry, I'm having trouble parsing what you're trying to convey with this post, so I may be way off in trying to respond.

                         

                        I do already have a highly modularized set of scripts with a master controller script we call xScript, which takes a series of parameters using what we call xTag (it's similar, I believe, to the method created by SixFriedRice, although I made it myself before hearing about that). I have ready at hand the ability to get to a layout, get to an object, find records, etc.If this is what you're talking about (and again, I mean no offense, but I'm not sure), then I'm a huge advocate of that approach, but I think it's off-topic. (I really do like this topic, and I'd suggest a new thread if I didn't think it was too large a topic for a productive discussion thread.)

                         

                        Where the .fmpsl comes in is mainly that I can restore a set of records and a sort order efficiently. There is unfortunately no "Get ( SortParameters )" function. Also other methods restoring a found set tend to be limited and tough from a performance standpoint, such as caching a list of keys/recordids and then doing a find request for each one is also not available to us.

                        • 9. Re: Creative uses for snapshot links
                          dmorgan

                          Hi Chris,

                           

                          Great idea, I've not had a chance to play with it but sounds like you could use this to edit the .fmpsl for external users?

                          I have server with local users and 2 dedicated external ip addresses and if there is a way to include alternate paths for the snapshot I haven't found it.

                           

                          Thanks for the post,

                          Denham

                          • 10. Re: Creative uses for snapshot links
                            Extensitech

                            I'm not sure I've completely understood some of the terms you're using ("external users", "dedicated external ip addresses", "alternate paths for the snapshot"), but...

                             

                            In the path to file section, note that the tag is "UniversalPathList"

                             

                            Or have I missed your point? (If so, I apologize, and would love to have clarification.)

                             

                            Chris Cain

                            Extensitech

                            • 11. Re: Creative uses for snapshot links
                              wimdecorte

                              "Alternate" as in "try this one first and if it fails then try the other one"?  Then no.  The snapshot is not a piece of code, it's just a static list that FM can read and figure out what to do.

                               

                              Why do you need two external IP addresses and why would the users sometimes need to use one or the other?

                              • 12. Re: Creative uses for snapshot links
                                Extensitech

                                I don't know that I've tested this as thoroughly as I should, Wim, but are you sure?

                                 

                                A .fmpsl with the pathlist like so:

                                 

                                <UniversalPathList>fmnet:/192.168.1.3/test.fmp12&#10;filewin:/C:/Users/ccain/Desktop/test.fmp12&#10;filewin:/C:/Users/ccain/Desktop/xBase_v12/test.fmp12</UniversalPathList>

                                 

                                ...will open from my desktop if the file is found, and from the subfolder "xBase_v12 if it's not. (sorry for the arbitrary names, I just grabbed a random folder). Note also that since it's a shared file, FM already added the local address so another user on my network could open it.


                                Could someone try this with two fmnet addresses?


                                I'm not sure what the "#10;" does. Seems to work with or without it, but I don't seem to be able to change it, for instance, to another number. Mystery.


                                BTW:


                                I'd sure like to know what other options are possible for some of these tags. There are a few things whose names imply that there are other options, but they're not used when creating a link from FM, so we can't know the alternatives without some documentation.


                                For example:


                                <SelectedRow type="nativeID" id="6">


                                ... implies that there's some other way to select a row besides using the "nativeID".


                                Chris Cain

                                Extensitech



                                • 13. Re: Creative uses for snapshot links
                                  wimdecorte

                                  Extensitech wrote:

                                   

                                  I don't know that I've tested this as thoroughly as I should, Wim, but are you sure?

                                   


                                   

                                   

                                  Actually, no.  Not as much as my post may have led on.  In my testing it did not work but perhaps I had a syntax error somewhere...

                                  • 14. Re: Creative uses for snapshot links
                                    Extensitech

                                    The syntax is a bit mysterious, as I said.

                                     

                                    You wouldn't happen to have any close FM friends who might be able to get us a "cheat sheet", would you?

                                     

                                    Chris Cain

                                    Extensitech

                                    1 2 3 Previous Next