11 Replies Latest reply on Mar 22, 2017 12:54 PM by BruceRobertson

    Simple script not working


      I am trying to copy the contents of a field from one TO to a related TO.

      The records in the starting layout are sorted by MemberID and the TOs are related by MemberID.

      Here's the script:


      The result are no changes made.

      Adding commands to change between sorted layouts during the Cut and Paste resulted in the pasting of identical, but not  correct and seemingly random, data into the correct field.

        • 1. Re: Simple script not working

          I made it work by placing the field from the parent TO into the original layout. Once I did that, the script worked. Now I can loop it.

          It seems counter-intuitive that this would be necessary, but I did learn something.

          • 2. Re: Simple script not working

            As you discovered, a limitation of copy/paste is that it requires the fields be on the layout. This is one reason experienced developers avoid copy/paste. The prefered method is to use Set Variable/Set Field, e.g.:


            Set Variable[ $id ; ID_field ]

            Set Field[ new_ID ; $id ]

            1 of 1 people found this helpful
            • 3. Re: Simple script not working

              Now for your next lesson.

              Don't use copy/paste to move data around like this. Use set field, or in most cases, set variable with set field to move data around.


              Copy/paste have the following problems:

              1. Copy replaces any data that the user may have previously copied to the clipboard with the data copied by your script step. If they then try to paste from the clipboard after your script has been executed, they get your script's data instead of the date that they copied--this will both confuse and annoy your users and is totally avoidable.
              2. Copy and paste only work if the referenced field is present on the current layout. A script that uses them may fail at some point in the future simply because you or another developer removed the field from the layout and didn't realize that the field was needed for your script.
              3. Copy and paste change the focus by putting the cursor into the referenced fields. This can trip script triggers with undesirable results due to the triggered script being performed. Not only is this an issue now, but it's possible that  a future developer (you or someone else) might add a trigger to the field and create a problem in the future.

              Set field and Set Variable do not have these issues.


              In your case, set field can replace both copy and paste since copying from one to the other on the same layout works. That indicates that you have a valid relationship between the two tables that matches to the correct record for the data that you want to move.


              Your original script is of a type when such a relationship link does not exist--maybe the current record is a new record and the needed match field doesn't have a value yet. It probably would have worked without the layout change that you made if you had moved line 3 to be after line 5.

              1 of 1 people found this helpful
              • 4. Re: Simple script not working

                Cancel that. It worked in two TOs but doesn't work in other and I cannot see any difference in how I've set them up.

                • 5. Re: Simple script not working

                  To repeat, your approach is not optimum.


                  To repeat, moving the data from field from a related table to a field from the layout's table will only work if the relationship linking the two is a) valid and b) matches to the record with the correct value.

                  • 6. Re: Simple script not working

                    Magnificent. Worked well.


                    (And I learned something using the Set Variable in the wrong order of steps in my first attempt.)

                    • 7. Re: Simple script not working

                      The Set Variable worked well. (But you knew that! ;-)

                      Here's a follow-up:

                      could I add other Set Field steps that would apply to fields in related TOs, not the active TO? I need to add this set variable in several TOs. Or do I need to do one table at a time?

                      • 8. Re: Simple script not working

                        lines 3 and 4 can be combined into a single step:


                        Set Field [ Child::memberIDCount'd ; Members::MemberIDcont'd ]


                        You only need to use set variable when the contents of the field from which you are copying data is not accessible at the point in time when set field needs to "paste" the data into the specified field. This can happen when:


                        You have to change layouts (that are based on different tables) between the "copy" and the "paste" steps

                        You have to change records

                        You've changed into Find Mode (Fields go blank in find mode unless the field is a global field.)


                        You aren't doing any of those things here so you don't need set variable.

                        • 9. Re: Simple script not working

                          I tried adding other Set Field steps referring to related tables.

                          Didn't get what I expected. So I'll do it one TO at a time.

                          • 10. Re: Simple script not working

                            There is a side benefit of setting the variable. It makes it easier to debug. I don't always have Set Variables involved. But often I will go that route, because I can then make the script more modular, and it can be used by other scripts by passing the value in as a script parameter.


                            Just another view on it for anyone else reading this thread.

                            1 of 1 people found this helpful
                            • 11. Re: Simple script not working

                              I'd like to suggest several things about your approach as revealed in this thread.


                              First of all, regarding this particular thread.

                              Maybe the answer is, don't do ANY of it.

                              Don't improve this script.

                              Get rid of it.

                              Learn how relations work and how to display related data.


                              Is that the right recommendation in this case?

                              We don't know. We can't know. You have not provided any meaningful description of what your data looks like.


                              While it is important to understand what a TO is, your use of the term here is not as informative as it should be.

                              A TO refers to an underlying base table. It may be another instance of the same table ( Contacts; Selected_Contact; Contact_spouse; etc). Or an instance from some other table ( Products, Orders, Line Items, etc).


                              "I will do this one TO at a time."



                              It really helps to use real world terminology for the table, fields, and workflow.

                              What are you updating with this script?

                              Would it be better just to learn how to display related data?

                              Certainly there are times when writing data from one record into another is the right thing to do.

                              Product price lookups, for instance.

                              There are other times when just displaying the related field data is the preferred approach.


                              Providing a vague and incomplete problem description isn't really helpful and makes the job of volunteer responders here much more uncertain and difficult.

                              You might think that you are doing something good this way - not burdening us with detail.

                              But providing a more complete problem description make it easier to answer your questions.

                              It also allows us to identify cases where a different approach might be better.