3 Replies Latest reply on May 16, 2013 8:57 AM by philmodjunk

    Creating a "universal" script with variables

    DavidRoy_1

      Title

      Creating a "universal" script with variables

      Post

           I'm trying to create scripts that will modify the contents of fields by calculation.  I'd like the user to click on a field, and that click sets the value of the field to the first in a value list, next click to the next value in the list, and so forth until it cycles back to the first value in a loop.

           I can get this to work by setting the field to be a button that fires a script, then using IF statements and the "Insert Text" script step; but I would have to create a seperate script for each field that way.  (I would like multiple fields to have this behavior, and multiple fields use the same value lists)  Also, obviously that step is just inserting text, so if I update the value list I'll have to update the scripts...

           My next step was to set a $variable for the ::fieldname, but it's not working as expected and I've tried multiple ways to have the script then navigate to the field which fired the script, but no joy.

            

           Here's the latest iteration of the script (which isn't working for reasons that'll be obvious to some I'm sure)

           -----------------------------

           Set Variable [$field; Table:"Tablename::" & Get(ActiveFieldName)]

           If [$field = ""]

                Set Field By Name [$field; "result1"]

                Commit Records/Requests [No dialog]

                Exit Script []

           Else If [$field = "result1"]

            

                Set Field By Name [$field; "result2"]

                Commit Records/Requests [No dialog]

                Exit Script []

                Else

                     Set Field By Name [$field; "result1"]

                     Commit Records/Requests [No dialog]

                End If

                -------------------------

                Once I solve the $field variable problem, I'll then need to solve the insert-text-by-value list problem.....

                Any help would be appreaciated.

            

        • 1. Re: Creating a "universal" script with variables
          philmodjunk

               Pass the TableOccurrence::FieldName of the field clicked to your script as a script parameter. Then you can use Get ( ScriptParameter ) with Set Field by Name to modify the contents of the field.

          • 2. Re: Creating a "universal" script with variables
            DavidRoy_1

                 Aha!  looks great.  Took me a few tries to realize I needed to put TableOccurance::FieldName into quotes when I specified it as a parameter for it to work.  Otherwise the Set Field by Name script step would return an error 102.

                 Here's the script I ended up with:

                 --------------------

                  

                  

                 If [GetField(Get (ScriptParameter)) = ""]
                  
                      Set Field By Name [Get (ScriptParameter); "result1"]
                  
                      Commit Records/Requests [No dialog]
                  
                      Exit Script []
                  
                 Else If [GetField(Get (ScriptParameter))= "result1"]
                  
                      Set Field By Name [Get (ScriptParameter); "result2"]
                  
                      Commit Records/Requests [No dialog]
                  
                      Exit Script []
                  
                 Else
                  
                      Set Field By Name [Get (ScriptParameter); "result1"]
                  
                      Commit Records/Requests [No dialog]
                  
                 End If
                 ------------------
                  
                 What I'd really like to do now is replace the "result1", "result2" text strings with a call to a defined value list.   I can't find a function that will accomplish this...so maybe this will turn into a really long project?  But the idea is I have defined a value list called ValueList with 3 values.  In my head I should be able to specify this in the Set Field By Name script step like so:
                      Set Field By Name [Get (ScriptParameter); ValueList::[1]]
                 Where 1 is the first value in the list. 2 the second value, and so on. 
                  
                 Do I have to create repeating field and then call the values out of it using MiddleValue?  Or am I missing a simpler and more obvious function? 

                  

                  

            • 3. Re: Creating a "universal" script with variables
              philmodjunk

                   I do not recommend that you put the table occurence::FieldName in quotes. That can result in your script suddently breaking on you should someone ever go to manage database and rename the field or the table occurrence.

                   Instead, use this expression: GetFieldName ( YourTableOccurrence::YourFieldName )

                   That will update automatically should such a name change occur.