11 Replies Latest reply on Dec 23, 2015 1:19 AM by globe11123

    Scripting problem

    globe11123

      Hi,

       

      Can someone correct my script? When the button is clicked it's not opening any layout.


      Don't worry about the second IF statement that is just to test if it opens another layout depending on the unit type.

       

      code.png

        • 1. Re: Scripting problem
          Extensitech

          By "it's not opening any layout", do you mean that you don't go to either the InspectionGGuard or Home layout?

           

          If so, this would indicate that, at least from the perspective in which you are starting, Units::Type doesn't equal G-Guard or G-Winch.

           

          Do you have FMP Advanced? Could you check the value of Units::Type in the data viewer? If not, could you add a custom dialog that shows the value?

           

          Chris Cain

          Extensitech

          • 2. Re: Scripting problem
            globe11123

            Fiddled with it a little bit and G-Winch is taking me to home.

             

            But when G-Guard is selected nothing is happening

             

            i'm using a trial at the moment before I get the pro advanced.

            • 3. Re: Scripting problem
              globe11123

              Found the problem, it had an invisible spacing at the end of the word! Doh!

              • 4. Re: Scripting problem
                Extensitech

                Trailing spaces... the bane of our existence!

                 

                You may want to consider checking against Trim ( Units::Type ), or even putting an auto-entry on that field so that leading and trailing spaces are automatically removed. Or even Trim ( Substitute ( Units::Type ; ¶ ; "" ) ) .

                 

                Chris Cain

                Extensitech

                • 5. Re: Scripting problem
                  globe11123

                  Ok I'll start using that right away.

                   

                  One thing I have noticed though is that once the ID is passed through to this next layout, whenever a new record is created the InspectionID is not being remembered.

                   

                  Is there a way round this?

                  • 6. Re: Scripting problem
                    Extensitech

                    If you create records via the relationship from Inspections, where InspectionID is the foreign key in the other table, FM will set this for you. If you create records outside the context of Inspections, FM can't "know" that that's what you want.

                     

                    You could set the inspectionID into a variable, or a global field, and then set it into new records using an auto-entry or new record script.

                     

                    Chris Cain

                    Extensitech

                    • 7. Re: Scripting problem
                      globe11123

                      Ok. The only thing is the layout would include records from lots of different InspectionID's.

                       

                      I could create a portal for this instead of going to a new layout but that would involve too many tabs.

                       

                      Is their a method of creating an instance of a portal related to the current InspectionID from clicking a button? This would look at the Unit::Type and open the appropriate Inspection's Table as there are like 10-11 different types of inspections we do.

                      • 8. Re: Scripting problem
                        Extensitech

                        globe11123 wrote:

                         

                        Is their a method of creating an instance of a portal related to the current InspectionID from clicking a button?

                        No.

                         

                        However, to your point about there being multiple records from different inspections... if you set, say, $$inspectioncurrent, then via auto-entry, or while in the script for creating new records, you could set InspectionID to $$inspectioncurrent. This wouldn't affect existing records, only new.

                         

                        Chris Cain

                        Extensitech

                        • 9. Re: Scripting problem
                          globe11123

                          So would I create an global variable in the Inspections table on Inspections::Id? Then change the InspectionsFkId to $$inspectioncurrent?

                           

                          Here's a reference to the tables involved. (GGuard is one of the inspections we do)

                           

                          Inspection.png

                          • 10. Re: Scripting problem
                            Extensitech

                            No, this wouldn't affect your relationships, etc.

                             

                            Set $$InspectionCurrent to Inspections::Id at the beginning of your script. (Or, you could set that variable onRecordLoad for the Inspections layout.)

                             

                            In InspectionGGuard::InspectionFkId, options, auto-entry tab, set an auto-entry by calculation to $$InspectionCurrent.

                             

                            That way, when you're on the InspectionGGuard layout, and add a new record, you'll automatically get the InspectionID from the last Inspection record you were on.

                             

                            Chris Cain

                            Extensitech

                            • 11. Re: Scripting problem
                              globe11123

                              Cheers chris, you've been a great help!