4 Replies Latest reply on Jun 14, 2011 3:01 AM by Ingrid

    Repeat a script for different fields

    Ingrid

      Title

      Repeat a script for different fields

      Post

      I have a script which filters data in a portal based on the average and  standard deviation of all rows contained in the portal.  The script needs to go through the portal rows several times, which  makes the script quite complex. The portal contains about 10 fields  (different parameters), for  which I want to repeat the procedure. However, now I have 10 almost  identical scripts for each parameter, and if I want to make a change in  the script I  have to do this 10 times, which could easily lead to mistakes. Is it  possible to create a script with e.g. blank field names, which can be  used  for different fields?

        • 1. Re: Repeat a script for different fields
          Kays

          heyy,

          you can set a global field in a table, and use that field in your script as a dynamic parameter

          K|Z

          • 2. Re: Repeat a script for different fields
            Ingrid

            Hi,

            Thanks for your reply. However, I wonder if using a global field works in a portal. Wouldn't I need one global field for each portal row then?

            Cheers

            • 3. Re: Repeat a script for different fields
              philmodjunk

              Not as a global field, but I'd use a global variable for this or even pass the data to the script in a script parameter. You can even pass the names of fields in your script parameter and then use Set Field By Name instead of Set field to modify different fields based on which field name was passed as a script parameter. getField can be used in the same way if you just need to "read" from a different field in order to use that data in a calculation.

              If you pass the fieldname in a parameter, you can use this expression in the paramter box: GetFieldName ( yourtable::yourFieldname). That way, if you change the field name later on, this script still passes the correct field name to the script.

              Here are some script step examples:

              Set Field By Name [ Get ( ScriptParameter ) ; //put your calculation here ]
              If [ getField ( Get ( ScriptParameter ) ) = 5 ]

              • 4. Re: Repeat a script for different fields
                Ingrid

                I hadn't used the Get(ScriptParameter) before, but it turned out to be very helpful.

                I have tried to use the combination GetField(GetValue(Get(ScriptParameter);2)) and this seems to do what I want.

                Thanks!