1 2 Previous Next 15 Replies Latest reply on Jun 14, 2016 10:23 AM by Benjamin Fehr

    Erratic behaviour on Script

    daniel.vareika

      Hello,

       

      I am finishing a script but is giving me some headackes.

      If I run it from the layout, no problem at all.

      If I run it from another layout and tell the script to go to that layout, it starts with the clock, with esc on it, and clears a field like in an infinite loop.

       

      Tried, refreshing, commiting, flushing cached joinresults, but no solution.

      Even I renamed the tables without spaces or accents.

       

      Any idea?

       

      Best

       

      Daniel

        • 1. Re: Erratic behaviour on Script
          jormond

          Can you post the script here? Print to a PDF and copy paste the text.

          • 2. Re: Erratic behaviour on Script
            daniel.vareika
            Perform Script [ “ULog Path” ]
            #Archive Log Data
            #Capture state
            Set Variable [ $RecordRef; Value:Get(RecordNumber) ]
            Set Variable [ $LayoutRef; Value:Get(LayoutName) ]
            #DV Va al layout engine.
            Go to Layout [ $$UL_LayoutEngine ]
            #Por lo menos el segundo.
            #Los siguientes dos comandos son necesarios para que no de error el script.
            #Le dice al custom Function si es un log o Prep Data
            #1 es Log
            #0 es Prep Data
            Set Variable [ $ClearLogPermit; Value:1 ]
            #Primer Loop entre records
            Show All Records
            Go to Record/Request/Page
            [ First ]
            Refresh Window
            [ Flush cached join results; Flush cached external data ]
            Commit Records/Requests
            [ Skip data entry validation; No dialog; Force Commit ]
            Loop
            #Inner Loop en el record que tiene todas las modificaciones
            Set Variable [ $counter; Value:ValueCount($$UL_LogDataField) ]
            Set Variable [ $$UL_LogDataField; Value:Persona_Puesto::LogData ]
            Loop
            Set Variable [ $LogEntry; Value:Let(
            LineN = GetValue($$UL_LogDataField; $counter);
            Substitute(LineN; " "; ¶)
            ) ]
            If [ GetValue($logEntry; 3) ≠ "[Log Prep]" ]
            Set Variable [ $$SQL; Value:Let (
            [
            LogEntry = Substitute(GetValue($$UL_LogDataField; $counter); " "; ¶);
            Layout = "UL_Log";
            Fields = "(DataID, EditTS, EditDate, EditTime, Account, EditedField, PreviousValue, NewValue)";
            SQLOpen = Char(34) & "INSERT INTO ";
            SQL1 = "VALUES (";
            SQLClose = ")" & Char(34) & " ; " & Char(34) & Char(34) & " ; " & Char(34) & Char(34) & " ; " & Char(34) & Char(34);
            Date = GetValue (LogEntry; 1);
            Year = Year(Date);
            Month = Month(Date);
            Day = Day(Date);
            Date = Year & "-" & Month & "-" & Day;
            DataID = "'" & Persona_Puesto::OID Persona Puesto & "'";
            EditTS = "TIMESTAMP" & "'" & Date & " " & GetValue (LogEntry; 2) & "'";
            EditDate = "DATE" & "'" & Date & "'";
            EditTime = "TIME" & "'" & GetValue (LogEntry; 2) & "'";
            Account = "'" & GetValue (LogEntry; 3) & "'";
            EditedField = "'" & GetValue (LogEntry; 4) & "'";
            PreviousValue = "'" & Substitute (GetValue(LogEntry; 5); "‡"; ¶ ) & "'";
            NewValue = "'" & Substitute (GetValue(LogEntry; 7); "‡"; ¶ ) & "'";
            Values = DataID & "," & EditTS & "," & EditDate & "," & EditTime & "," & Account & "," &
            EditedField & "," & PreviousValue & "," & NewValue;
            SQL = "BE_FileMakerSQL ( " & SQLOpen & Layout & Fields & SQL1 & Values & SQLClose & " )"
            ];
            Evaluate ( SQL )
            ) ]
            // Set Variable [ $$BeError; Value:BE_GetLastDDLError ]
            End If
            Set Variable [ $counter; Value:$counter-1 ]
            #Va borrando linea a linea pasada al Log
            Set Field By Name [ $$UL_LogDataFieldName; Let(
            Nlog = LeftValues($$UL_LogDataField; $counter);
            Left(Nlog; Length(Nlog))
            ) ]
            Commit Records/Requests
            [ Skip data entry validation; No dialog ]
            Exit Loop If [ $counter=0 ]
            End Loop
            #DV OK - Luego de pasar los registros al log, lo limpia y pone los preps nuevos
            Set Field By Name [ $$UL_LogDataFieldName; Let([
            $ClearLogPermit = 0;
            PrepData = UltraLog( ""; Get(CurrentTimestamp); $$UL_FieldsToLog);
            $ClearLogPermit = 1];
            PrepData
            )
            /*Note:
            The prep procedure overwrites the logs
            on the current record (if any) with prep
            data.*/ ]
            
            Go to Record/Request/Page
            [ Next; Exit after last ]
            Set Variable [ $$UL_LogDataField; Value:Persona_Puesto::LogData ]
            #DV - End inner loop en el record
            End Loop
            Commit Records/Requests
            [ Skip data entry validation; No dialog ]
            #Restore state - vuelve a donde estaba (layout y record)
            Go to Layout [ $LayoutRef ]
            Go to Record/Request/Page [ $RecordRef ]
            [ No dialog ]
            ##
            
            • 3. Re: Erratic behaviour on Script
              daniel.vareika

              Sorry Joshua,

               

              It lost some readability in the conversion to PDF and back to here.

               

              Best,


              Daniel

              • 4. Re: Erratic behaviour on Script
                Benjamin Fehr

                IF you're using FMP-Advanced, start the script with Script-Debugger activated to check the script step-by-step.

                "Focus" is what catches my mind: Has FM focus on the required layout when script performing a corresponding task?

                 

                If I run it from another layout and tell the script to go to that layout, it starts with the clock

                Means it probably has no focus on "that layout".

                For tests, you can use

                     New Window (with negative coordinates to have it out of sight)

                     Goto Layout "that layout"

                          Perform Script steps which requires "that layout"

                     Close Window [current] = "that layout"

                • 5. Re: Erratic behaviour on Script
                  daniel.vareika

                  Thank you Benjamin,

                   

                  Tried what you recommended (opening a new window and debugging step by step).

                  Same results.

                  The problem is erratic.

                   

                  Most of the time it makes it.

                  On few ocasion it does not.

                   

                  The only thing that works rock solid, it is if I start from the layout.

                  Very weird and hard to trace.

                  Maybe it is a bug? would love though that it is my fault

                   

                  Any help from the community will be welcomed.

                   

                  Best,


                  Daniel

                  • 6. Re: Erratic behaviour on Script
                    TSPigeon

                    daniel.vareika:

                     

                    I am going to move this thread from the FileMaker Community Feedback Space, which is specifically for input on the Community itself, to the Discussions Space where you should receive more views and potentially more advice!

                     

                    TSPigeon

                    FileMaker, Inc.

                    • 7. Re: Erratic behaviour on Script
                      Benjamin Fehr

                      I am going to move this thread from the FileMaker Community Feedback Space, which is specifically for input on the Community itself, to the Discussions Space where you should receive more views and potentially more advice!

                      … and if we can't find a possible cause, maybe even further to the Report a Product Issue space

                       

                      daniel.vareika

                      If this stays erratic, don't hesitate to send this in as a Issue Report with detailed information:

                      Bug Report Template

                      • 8. Re: Erratic behaviour on Script
                        keywords

                        The thing you are experiencing is this—Filemaker is highly context specific. If your script runs perfectly if you initiate it from a certain layout, then that must be the context it requires to begin with. So, to make sure it ALWAYS runs from that context make the FIRST STEP in the script Go to Layout, and name the one that works. If you are already on that layout this step will do nothing, but if you initiate the script from anywhere else in your solution it will navigate to that layout and then run properly. NOTE: if you do this, you probably should also add a Go to Original Layout step right at the end, so users end up back where they began.

                        • 9. Re: Erratic behaviour on Script
                          daniel.vareika

                          Keyword,

                           

                          This is already present in the script.

                          And the problem persists.

                           

                          Best,

                           

                          Daniel

                          • 10. Re: Erratic behaviour on Script
                            keywords

                            I beg to differ. The script you have posted does not BEGIN with a go to context step, which is what I suggested.

                            • 11. Re: Erratic behaviour on Script
                              daniel.vareika

                              So if I undersand correctly, you are saying to put step 01 after 07.

                              Simply that?

                              I will try.

                              • 12. Re: Erratic behaviour on Script
                                keywords

                                More precisely I would say move step 07 to the start of the script—which may be what you mean, of course. When you do this it will become step 01, and the rest will renumber accordingly.

                                • 13. Re: Erratic behaviour on Script
                                  daniel.vareika

                                  It is absolutely weird, but it works!

                                  Chaged only line 01. after line 07. so that I could capture in which Layout and record I was so as to return to it.

                                   

                                  Still I do not get it....

                                   

                                  Thanks a lot, would not have thought off!

                                   

                                  Best,

                                   

                                  Daniel

                                  • 14. Re: Erratic behaviour on Script
                                    keywords

                                    To reiterate what I said before, context is king. It is like this. You have two lists in your pocket: a shopping list and a list of things you have to do at work today. In your mind you say to yourself, do the first item on the list, but if you don't first establish which list you are talking about you might end up buying a tube of toothpaste, when you really meant to write a letter to your boss. Establish the context (take out the correct list, or go tho the correct layout), then do the thing.

                                    1 2 Previous Next