2 Replies Latest reply on Oct 6, 2015 2:56 PM by keywords

    Help with script

    thong127

      Hello All,

       

      I have a script to view or save my Materials base on their category.

       

      Allow User Abort [off]

      If Get(ScriptParameter) = "API"

      Show Custom Dialog ["View or Save"; Do you want to View Only or Save as Excel?

      If Get [(LastMessageChoice)] = 1

      Perform Script API

      Go to Layout ["Materials List View' (Materials)

      End If

      If Get [(LastMessageChoice)] = 2

      Perform Script API

      Go to Layout ["Materials List View" (Materials)

      Perform Script [Prep to export]

      End If

      If Get [(LastMessageChoice)] = 3

      Go to Layout[original layout]

      End If


      If Get(ScriptParameter) = "Bottles"

      Show Custom Dialog ["View or Save"; Do you want to View Only or Save as Excel?

      If Get [(LastMessageChoice)] = 1

      Perform Script Bottles

      Go to Layout ["Materials List View' (Materials)

      End If

      If Get [(LastMessageChoice)] = 2

      Perform Script Bottles

      Go to Layout ["Materials List View" (Materials)

      Perform Script [Prep to export]

      End If

      If Get [(LastMessageChoice)] = 3

      Go to Layout[original layout]

      End If

       

      f Get(ScriptParameter) = "Capsules"

      Show Custom Dialog ["View or Save"; Do you want to View Only or Save as Excel?

      If Get [(LastMessageChoice)] = 1

      Perform Script Capsules

      Go to Layout ["Materials List View' (Materials)

      End If

      If Get [(LastMessageChoice)] = 2

      Perform Script Capsules

      Go to Layout ["Materials List View" (Materials)

      Perform Script [Prep to export]

      End If

      If Get [(LastMessageChoice)] = 3

      Go to Layout[original layout]

      End If


      .....and so on


      My Custom Dialog box set up is below


      Default Button (View) ; Button 2 ( Save) ; Button 3 (Cancel)


      Can you please help me simplify my script.


      Thank you so much


      Thong


       


        • 1. Re: Help with script
          erolst

          thong127 wrote:

          Can you please help me simplify my script.

           

          You cannot directly abstract the script calls; one approach would be to use the fmp:// protocol (from v13.02), or try to consolidate these scripts too; either way, use the script parameter.

           

          But you can consolidate all that other stuff:

           

          Allow User Abort [off]

          Show Custom Dialog ["View or Save"; "Do you want to View Only or Save as Excel?" ]

          # [ 1 = VIEW, 2 = SAVE, 3 = CANCEL ]

           

          If [ Get ( LastMessageChoice ) = 3 ]

            Go to Layout [ original layout ]

            Exit Script

          End If

           

          # [ for View and Save ]

          If [ Get ( ScriptParameter ) = "API" ]

            Perform Script [ API ]

          Else If [ Get ( ScriptParameter ) = "Bottles" ]

            Perform Script [ Bottles ]

          Else If [ Get ( ScriptParameter ) = "Capsules" ]

            Perform Script [ Capsules ]

          Else If [ etc. ]

            # [ at a guess, you could consolidate these scripts too by passing on the script parameter ]

          End If

          Go to Layout ["Materials List View' (Materials)

           

          # [ only for Save ]

          If [ Get ( LastMessageChoice ) = 2 ]

            Perform Script [ Prep to export ]

          End If

          • 2. Re: Help with script
            keywords

            There is an enormous amount of repetition. consider:

             

            Allow User Abort [off]

            Show Custom Dialog ["View or Save"; Do you want to View Only or Save as Excel?

            If Get [(LastMessageChoice)] = 3

                  Go to Layout[original layout]

                  Exit script

            End If


            If Get(ScriptParameter) = "API"

            Perform Script API

              If Get [(LastMessageChoice)] = 1

                  Go to Layout ["Materials List View' (Materials)

                  Exit script

              Else If Get [(LastMessageChoice)] = 2

                  Go to Layout ["Materials List View" (Materials)

                  Perform Script [Prep to export]

            End If


            If Get(ScriptParameter) = "Bottles"

            Perform Script Bottles

              If Get [(LastMessageChoice)] = 1

                  Go to Layout ["Materials List View' (Materials)

                  Exit script

              Else If Get [(LastMessageChoice)] = 2

                  Go to Layout ["Materials List View" (Materials)

                  Perform Script [Prep to export]

            End If

             

            If Get(ScriptParameter) = "Capsules"

            Perform Script Capsules

              If Get (LastMessageChoice) = 1

                  Go to Layout ["Materials List View' (Materials)

                  Exit script

              Else If Get [(LastMessageChoice)] = 2

                  Go to Layout ["Materials List View" (Materials)

                  Perform Script [Prep to export]

            End If