11 Replies Latest reply on Mar 19, 2014 3:25 PM by chronister

    Catch errors for images that may be missing

    chronister

      Hello all,

       

      I am moving right along with my supplier quoting system that a few of you helped me out with previously. Thank you for that.

       

      I am now faced with needing to link 10,000 images to a container field. I am able to do it without much issue, except when it comes to missing files. I have 12,441 records I am targeting, and 10,245 images. So I am missing around 2200 images, which is not a big deal and there is noting I can do about that as it is controlled by the supplier.

       

      So how do I loop through and skip these fields that have missing images or capture the dialogs so that it does not interfere with script operation?

       

       

      I have a flag field to catch many of the missing images, but there are still some missing images that are not being handled.

       

      Any help would be appreciated.

       

      Thanks,

       

      Nathan

        • 1. Re: Catch errors for images that may be missing
          Stephen Huston

          It's not clear how your images are being matched up to existing records.

           

          Have you considered using an intermediary table in a separate file to import the images, capturing file names, paths, or whatever you need to match them to existing records? Then parse out that information and use it as a match-field for updating via an import that updates existing records based on a match field?

          • 2. Re: Catch errors for images that may be missing
            chronister

            Sorry, I did not specify needed information.

             

            I have a products table that holds the products for this supplier, I have a table that holds the pricing information for each item linked to forementioned table via SNSCode (all these are linked via SNSCode).

             

            I then have 2 more tables (1 is just a temp table to accomplish what I need). The first is ssImages. This holds the image, color information and SNSCode for each item. Since each product may have multiple images for it, I have it setup like this so I can have a one to many relationship with ssProducts and ssImages.

             

            I have a temp table that holds image locations for each item (each item has a front image, side image and back image) as well as the SNSCode and color for each item and a field to mark if the image is missing or not. This field is not completely accurate. It is as accurate as I can get it though.

             

            My script is looping through that temp table (StyleImages2) and grabbing the front image name and setting to variable along with a few other variables. It then opens the ssImages table and creates a new record and inserts the data. This is where I am getting stuck.

             

            I have 10,245 images of 12,441 images in a folder (container folder for this field) and am needing to handle the missing images in the script so that it bypasses any records that do not have images available to insert.

             

            Hope this helps and let me know if you need more inforamation or need to see DB schema and such.

             

            Thanks,

             

            Nathan     

            • 3. Re: Catch errors for images that may be missing
              eduncle

              I'm still not clear on what data you are using to match images to each record, I get that you don't have all the images and you have a field that partially detects missing images, but how are you matching those images on import and what is that detection field doing exactly?

               

              I assume you have ruled out solutions such as using an 'IsEmpty( field )' calculation against the container field(s) in question, or running a Get(LastError) between each import to detect failures?

              • 4. Re: Catch errors for images that may be missing
                eduncle

                I should have mentioned, if you use 'Is(Empty)' in a field calculation, don't forget to UNtick 'Do not evaluate if all referenced fields are empty'

                • 5. Re: Catch errors for images that may be missing
                  chronister

                  Here is an image of my DB Schema for these tables. I have ssProducts, ssImages and ssPrices linked via snsCode (which I need to standardize in the spelling now that I look at it), the StyleItems2 is a table that was created via a spreadsheet given to me by the supplier and contains the image names and SNS code. It had more info, but this is all I needed for my purposes. My images have been downloaded and placed inside the open storage location that the container field stores things on the system.

                   

                  So my script is looping through StyleItems2, and setting variables for SNSCode, color, frontImage and missing. It then goes to the ssImages table and IF[NOT $missing = 1], then it skips that row as it is one I have determined that is missing otherwise it attempts to insert the image into the container and writes the code and color variables to ssImage.   So I need a way to determine if the image it is attempting to insert actually lives on the hard drive with the others, or if it is missing. If it is missing on the filesystem, then I need a way to skip that record or at least catch the errors it produces so it stops making the script die

                   

                  I hope this helps make things more clear and you understand the problem I face.

                  schema.png

                   

                  Thanks,

                   

                  Nathan    

                  • 6. Re: Catch errors for images that may be missing
                    Stephen Huston

                    It sounds like some fairly simple If/Else test within the loop to determine if images are available or not could keep the update from happening for missing images.

                     

                    You could even have a global container field with an image which says something like "No Product Image Available" that would be inserted instead (using the If/Else test within the loop) if the image record was empty or does not exist, so that all fields had "some" image to display.

                    • 7. Re: Catch errors for images that may be missing
                      eduncle

                      chronister wrote:

                       

                      My images have been downloaded and placed inside the open storage location that the container field stores things on the system.

                       

                      I think the problem you're having is getting the images in to FileMaker. Did you manually put stuff in the open container folder?  If so, that isn't supported by FM.

                       

                      Why not do something like this:-

                       

                      1 - Put your images in a plain folder, somewhere outside of FM container space, eg. your desktop/MyFolder.

                      2 - Create 3 container fields in StyleItems2 eg FrontPic, SidePic, BackPic

                      3 - Create a script which loops through the records in StyleItems2 doing something like: -

                      Loop

                      Go To Layout (a Layout based on the StyleItems2 table)

                      Set Variable [$SNSCode; Value:StyleItems2::SNSCode]

                      Set Variable [$frontImagePath; Value:"filewin:" & get(DesktopPath) &" MyFolder/"& StyleItems2::FrontImage]

                      Set Variable [$sideImagePath; Value:"filewin:" & get(DesktopPath) &" MyFolder/"& StyleItems2::SideImage]

                      Set Variable [$backImagePath; Value:"filewin:" & get(DesktopPath) &" MyFolder/"& StyleItems2::BackImage]

                      Go To Layout (a Layout based on the ssImages table)

                      New Record / Request

                      Set Field [ssImages::SNSCode; Value:"$SNSCode"]

                      Go to Field [Select/Perform; ssImages::image]

                      Insert Picture ["$frontImageFilePath"]

                      If (GetLastError)

                         Delete Record / Request [Perform without Dialog]

                      End If

                      New Record / Request

                      Set Field [ssImages::SNSCode; Value:"$SNSCode"]

                      Go to Field [Select/Perform; ssImages::image]

                      Insert Picture ["$sideImagefilepath"]

                      If (GetLastError)

                         Delete Record / Request [Perform without Dialog]

                      End If

                      New Record / Request

                      Set Field [ssImages::SNSCode; Value:"$SNSCode"]

                      Go to Field [Select/Perform; ssImages::image]

                      Insert Picture ["$backImagefilepath"]

                      If (GetLastError)

                         Delete Record / Request [Perform without Dialog]

                      End If

                      Go To Layout (a Layout based on the StyleItems2 table)

                      Go To Record / Request [Next: Exit after last]

                      End Loop

                       

                      I am sure you could make this MUCH slicker and you may need to tweak it for mac filenames etc.

                      • 8. Re: Catch errors for images that may be missing
                        chronister

                        Well that along with some more research gave me the solution.

                         

                        Rather than detecting if the image is missing and skipping that row, I set an alternate image to be inserted. I simply created an Image not Found graphic and set it's path to be my alternate.

                         

                        It is working as intended now. I am importing and it freezes up around every 3000 rows. I then kill the task and re-open. I had set a UID as a calculation field which gives me $snsCode_$Color as the data which allows me to skip that row if it is already there.

                         

                         

                        So thank you for the assistance and ideas. This actually works out better as it will give me all the colors that a particular item comes in even if I don't have an image of it.

                         

                        Thanks,

                         

                        Nathan    

                        • 9. Re: Catch errors for images that may be missing
                          chronister

                          I placed the images inside that folder for scripting purposes. I figured if the images were already in the destination folder, the script would run faster.... but I discovered that it was creating a duplicate of the files and naming them <filename>_1.jpg.

                           

                          I think I have something working here. It is running and seems to be doing what it is supposed to.

                           

                          Nathan     

                          • 10. Re: Catch errors for images that may be missing
                            Stephen Huston

                            I would definitely place images to be imported elsewhere than in FM's open storage area, as that space is reserved for the FM application, and anything that changes it could conceivably cause FM to treate images as having been "tampered" with, putting the integrity of the database at risk.

                             

                            Open storage is intended ONLY for users to be able to copy unopened files from it, not to add, change, or even open such files for a peek within the storage area.

                            • 11. Re: Catch errors for images that may be missing
                              chronister

                              Yeah, I moved them out of the container folder as it was creating duplicates.

                               

                              I am almost done with this import process. I have had to fool with it and such but it is almost there.

                               

                               

                              Thanks all