4 Replies Latest reply on May 9, 2017 2:41 PM by HB

    Inconsistencies with inserting an image via script


      I am having mixed results with this portion of a script that is to insert an image into a record from a file whose name is prefixed by the WO_Number of the record.  Sometimes the image gets inserted but the odd time it doesn't. This has happened with different file/records on different days. The P drive source is a Local folder that is shared & has been mapped as P on this computer where I am finding some inconsistencies, and I would prefer to keep it that way as in the future the script could be run from another computer on the network.


      Any red flags here on my method? I havn't really looked at error trap routines (ever) but I am guessing that would be my next option????


      Also - I am thinking of moving the 'Go to Field [ Images::Picture ]' step before the loop - that shouldn't be a problem should it?


      Thanks in advance.


      • Show All Records
      • Freeze Window
      • Sort Records [ Keep records in sorted order; Specified Sort Order: Wrk_Ordr::WO Number; descending ] [ Restore; No dialog ]
      • Go to Record/Request/Page [ First ]
      • #Insert Image File Refs
      • Loop
      • Set Error Capture [ On ]
      • Go to Field [ Images::Picture ]
      • Set Variable [ $fn; Value:"imagewin:/P:/Gallery/Wall600/" & Wrk_Ordr::WO Number & ".600.jpg" ]
      • Insert Picture [ “$fn” ] [ Reference ]
      • If [ $HighestPicUpdated ="" ]
      • If [ Get ( LastError ) = 0 ]
      • Set Variable [ $HighestPicUpdated; Value:Wrk_Ordr::WO Number ]
      • End If
      • End If
      • Set Error Capture [ Off ]
      • If [ Wrk_Ordr::Work Progress = "received" ]
      • Set Field [ Wrk_Ordr::BR_ImageChecked; 1 ]
      • End If
      • Go to Record/Request/Page [ Next; Exit after last ]
      • End Loop
        • 1. Re: Inconsistencies with inserting an image via script

          There is no go to layout step. THat may or may not cause a problem, but steps that start with "insert"---such as insert picture cannot insert data unless the target field is present on the current layout.


          I would not move the Go To field script step except maybe to put it after the set variable step.

          • 2. Re: Inconsistencies with inserting an image via script

            thanks PhilModJunk, I added the go to layout but can't see how that was the problem in this instance since I know what layout it was always run from. I thought the script would run faster looping through 4000plus records by taking the Go To Field script outside of the loop & before it. We don't have images for every WO so I simply ignored errors.

            • 3. Re: Inconsistencies with inserting an image via script

              The risk to pulling the go to field out of the loop is more than the slight change in speed is worth. The change from record to record could, in some cases move the focus to the wrong field. It might not at the moment, but a future change in the layout might. In fact, using a utility layout for this script with no script triggers and which is never exposed to the user would be a very good idea.


              You haven't really indicated exactly how this is inconsistent, BTW. A more detailed description of how it fails when it fails may clue some of us in as to possible issues.


              For example, when it fails, does it fail for all records that the script tries to insert, or does one iteration of this loop insert a record and the next one does not.

              • 4. Re: Inconsistencies with inserting an image via script

                As far as I can tell - script runs fine but after running it I find one of the images didn't actually get inserted. When I re-run it it does get inserted. The record happened to be somewhere in the middle of the sorted records. That is all I know.