14 Replies Latest reply on Jan 8, 2014 11:52 AM by philmodjunk

    Storing multiple key/value pairs in FileMaker Pro12

    maddy

      Title

      Storing multiple key/value pairs in FileMaker Pro12

      Post

           Hello,

           I am working on a record which stores filepath of different images. I have a button which opens the filepath. While opening the file it always ask the credentials. I wrote a script in that, it ask the credentials when the user first time click for that path (fetch the path source which needs the credentials)and afterwards it will open the image directly on clicking the button. For this, I used global variable. When the value of the global variable is 1, it ask for credential and when it increases it automatically open the filepath. This solution is working only when I have a single filepath staring from, say '\\path-fst1.ad.XXX.edu\......

           When I have filepaths staring from different sources like "\\PATH-FSH.dyn.hs.XXX.edu\..." in this case I need to store global variable corresponding to each one. My problem is that whenever I get a different source in the filepath, I need to incease its corresponding filecount by 1. 

           How do I achieve this. Is there a solution to store filepath_source and corresponding filecount as a key/value pair in FileMaker Pro. Please help!!! Let me know if I am not clear and you need further details.

            

      filePath_Script.png

        • 1. Re: Storing multiple key/value pairs in FileMaker Pro12
          philmodjunk

               I need more detail to understand better what you are trying to do.

               

                    I have a button which opens the filepath.

               Are you using Open URL, a container field or a web Viewer to do that?

               

                    in this case I need to store global variable corresponding to each one.

               There are several methods that might work, but I don't understand why that would be necessary. Why can't you keep this data in fields of a related table of records where each such value is in a different record?

               1) A single variable can hold a return separated list of values.

               2) A variable can be a repeating variable where $VariableName[1] refers to one value, $VariableName[2] refers to another and so forth.

               3) A script can create variables where the exact name of the variable is produced by a calculation:

               Set Variable [$Dummy ; value: Evaluate ( "Let ( $VariableName" & $K & " = " & Table::Field & "; 1 ) " ) ]

               By changing the value of $K, the value of Table::Field can be assigned to variables named $VariableName1, $VariableName2 and so forth... (It also assigns the value 1 to $Dummy.)

          • 2. Re: Storing multiple key/value pairs in FileMaker Pro12
            maddy

                 Hi Phil,

                 Thanks for responding. I used Open URL to open the filepath. I attached the script and the form I am working on. Still, I am not clear how to proceed with the solution. I have hardcoded the filepath source to keep track of their corresponding count which I need to modify. Please guide me if there is another way I can achieve this. 

                 I was also looking to various solutions related with repeating values but I didn't understand how to implement it in my case.

                 Waiting for your response. Let me know if you need further detail. Thanks!

                  

            • 3. Re: Storing multiple key/value pairs in FileMaker Pro12
              philmodjunk

                   The uploaded image wasn't yet visible when I posted my previous response.

                   I could use a "big picture" summary of what you are trying to do with this script.

                   And please describe the ImagePath::ImagePath field. Is this a text field? How is data entered into it?

                   You appear to be using a custom function: GetChar, what does it do?

                   I'm still very unclear on what you are trying to do here, but I'll share a few general facts about file paths, variables and image files:

                   a) If you insert an image file into a container field with the "store a reference" option enabled, the file path to that image file is entered into the container field and can be extracted for storage in a text field and can then be used with Open URL to open the file. You can also use export field contents to open a copy of the file directly from the container field

                   b) If an image file is inserted with the Insert File method and with "store a reference" enabled, you can double click the container field to open the original copy of the file so long as external storage is not specified for the field and the field is not "optimized for interactive content".

                   c) There's a thread with an "exploration file" you can download that provides a lot of info about File Paths, $Path variables, container fields and the script steps that can be used with them: Exploring the use of a $Path Variable in Scripts

                    

                    

              • 4. Re: Storing multiple key/value pairs in FileMaker Pro12
                maddy

                     Hi Phil,

                     Here, I don't have an issue with filepath. I have problem to store multiple values in a variable.

                     I want to have an array of variable something like, so that I can keep track of each filepath source (which I need for entering credentials):

                     $filecount [$filePath, $$fileCount] 

                     i.e.

                     $filecount ["\\path-fst1.ad.XXX.edu\", 2] - Then open the whole imagepath directly by Open URL.

                     $filecount ["\\PATH-FSH.dyn.hs.XXX.edu\", 1] - Then open \\PATH-FSH.dyn.hs.XXX.edu\ for entering credential.

                     Below is the description of my script:

                1. ImagePath::ImagePath is a text field and is used to store a filepath. eg. "\\path-fst1.ad.XXX.edu\Public\Andra Kovalovsky\MASC STUDY SCANNED\MASC\CC12-24976\SALIVARY MASC Lip  SC12-24976.bif".

                2. Variable $$path stores the filepath Source (substring of the filepath) i.e. \\path-fst1.ad.XXX.edu\ by using GetChar. I am getting this folder because it asks the user credential first. Because user can not open the whole path "\\path-fst1.ad.XXX.edu\Public\Andra Kovalovsky\MASC STUDY SCANNED\MASC\CC12-24976\SALIVARY MASC Lip  SC12-24976.bif" by using open URL.

                3. The very first time when user click on the button to open the image path, $$path = \\path-fst1.ad.XXX.edu\ and its corresponding count $$globalVar1 = 1. Open the  folder \\path-fst1.ad.XXX.edu\. So, user can enter his credentials.

                     For the second time, when $$path = \\path-fst1.ad.XXX.edu\ , its corresponding count $$globalVar1 = 1+ 1 = 2. In this case Open the whole path "\\path-fst1.ad.XXX.edu\Public\Andra Kovalovsky\MASC STUDY SCANNED\MASC\CC12-24976\SALIVARY MASC Lip  SC12-24976.bif". 

                User has to enter his credential at the first time for that image path folder (\\path-fst1.ad.XXX.edu\). Next time, he can directly view that image by opening the whole path. It is working in case when I have only single path which checks for credential, say \\path-fst1.ad.XXX.edu\.

                     But, if I have multiple source eg. \\PATH-FSH.dyn.hs.XXX.edu\CoreoFiles$\MBG\Salivary\Acinic cell\03-22256 A3.bif. Then how I can keep track of its corresponding count. (First time open: \\PATH-FSH.dyn.hs.XXX.edu\ for credential then afterwards open the whole path to view the image).

                     Please let me know if I am still not clear.

                      

                • 5. Re: Storing multiple key/value pairs in FileMaker Pro12
                  philmodjunk

                       The fact that you need to open the directory to the file's location first, then open the files is the key detail that was missing in my understanding of the issue. From what I can understand, you need to know which folders have been opened by the current user so that you don't try to open an image from a folder for which the user hasn't yet entered credentials. Is that correct?

                       

                            $filecount ["\\path-fst1.ad.XXX.edu\", 2] - Then open the whole imagepath directly by Open URL.

                       You could use $$FilesOpen where $FilesOpen [2] returns "\\path-fst1.ad.XXX.edu\".

                       But you may find it easier to work with a return separated list of values instead of such a repeating variable. With a return separated list of values, you can use the FilterValues function to determine whether a particular value exists in the list.

                  • 6. Re: Storing multiple key/value pairs in FileMaker Pro12
                    maddy

                         Hi Phil,

                         Thanks for responding. Sorry for the delay. Your understanding "you need to know which folders have been opened by the current user so that you don't try to open an image from a folder for which the user hasn't yet entered credentials. " is correct.

                         Can you explain the solution for that. How I can keep track of each individual directory in this case. How to know whether user has already enter the credential for the directory so that I can open the image from the filepath. Can you explain me how to use return separated list of values? Please explain me in detail and it would be great if you can help me with scripts if there are any.

                         Thanks in advance.

                         

                               

                          

                    • 7. Re: Storing multiple key/value pairs in FileMaker Pro12
                      philmodjunk

                           I'm going to skip one detail as I think you have this part working--the calculation to extract the folder path from the file's file path.

                           Here's a List based approach to keeping track of which folders have been accessed by the current user:

                           Set Variable [$Folder ;value: Your calculation to extract file path to folder goes here ]
                           Open URL [....
                           If [ IsEmpty ( FilterValues ( $$FolderList ; $Folder ) ) // First time this folder has been accessed ]
                              Set Variable [ $$FolderList ; value: List ( $$FolderList ; $Folder ) ]
                           End If

                           If you need script steps to remove $Folder from $$FolderList, let me know.

                      • 8. Re: Storing multiple key/value pairs in FileMaker Pro12
                        maddy

                             I already did the calculation to extract the folder path from the filepath.

                             In script $Folder is used to store the folder extracted from filepath.

                             I have few question:

                             1. As I understood, $$FolderList should be declated as an empty string. "Open URL [If [ IsEmpty ( FilterValues ( $$FolderList ; $Folder ) ) ]" should open the $Folder at the first time and then you are adding that $Folder to $$FolderList by this code: Set Variable [ $$FolderList ; value: List ( $$FolderList ; $Folder ) ].

                        Whether the whole code goes under Open URL (with if-End if)? 

                        2. Otherwise, I have to open the whole filepath to see the image. That Open URL will go after this?

                              

                              

                        • 9. Re: Storing multiple key/value pairs in FileMaker Pro12
                          philmodjunk

                               You only need use:

                          Open URL [$Folder ]

                               to open the folder

                          • 10. Re: Storing multiple key/value pairs in FileMaker Pro12
                            maddy
                                 

                            Set Variable [$Folder ;value: Your calculation to extract file path to folder goes here ]
                            Open URL [$Folder]

                                 In this case, each time it opens the folder, which I don't want. I want to open it for the first time, afterwards it directly open the whole filepath to view the image.

                            • 11. Re: Storing multiple key/value pairs in FileMaker Pro12
                              philmodjunk

                                   Sorry, my original example puts Open URL in the wrong place, and you probably don't want to add $Folder to the list if the user is unable to use their credentials to open that folder.

                                   Set Variable [$Folder ;value: Your calculation to extract file path to folder goes here ]
                                   If [ IsEmpty ( FilterValues ( $$FolderList ; $Folder ) ) // First time this folder has been accessed ]
                                      Open URL [$Folder]
                                      IF [not Get ( LastError ) //only add $Folder to list if there were no errors opening the folder ]
                                        
                              Set Variable [ $$FolderList ; value: List ( $$FolderList ; $Folder ) ]
                                      End If
                                   End If

                              • 12. Re: Storing multiple key/value pairs in FileMaker Pro12
                                maddy

                                Set Variable [$Folder ;value: Your calculation to extract file path to folder goes here ]
                                If [ IsEmpty ( FilterValues ( $$FolderList ; $Folder ) ) // First time this folder has been accessed ]
                                   Open URL [$Folder]
                                             
                                 Set Variable [ $$FolderList ; value: List ( $$FolderList ; $Folder ) ]

                                Else

                                     Open URL ["Field containing filepath"]

                                End If

                                - It worked. Thanks a lot. smiley

                                • 13. Re: Storing multiple key/value pairs in FileMaker Pro12
                                  maddy

                                       Hi Phil,

                                       Thanks for the solution.

                                       Can you explain the steps to remove $Folder from $$FolderList? I just wanted to know for future reference. Thanks!

                                        

                                  • 14. Re: Storing multiple key/value pairs in FileMaker Pro12
                                    philmodjunk

                                         The following works for any return separated list of values. I takes special precautions to ensure that partial text matching doesn't delete text from the list that should not be deleted.

                                         Set Variable [ $$FolderList ; //put calculation shown below here ]

                                         Let ( TheList = Substitute ( ¶ & $$FolderList & ¶ ; $Folder ; ¶ ) ;
                                                  Middle ( TheList ; 2 ; Length ( TheList ) - 2 )   // this line removes the extra ¶ characters added in the previous line.
                                               )