3 Replies Latest reply on Apr 12, 2016 5:25 AM by Mike_Mitchell

    Trying to create records in another table

    Ben_B94

      But it only creates 1 record.

       

      go to layout (locations)

      go to record/request [first]

      set variable $listLocation ; get(total record count)

      set variable $counter ; 1

       

      loop

            set variable $location ; Location::location_ id

            freeze window // not sure i'm using this right

            go to layout [Hire]  

            new record/request

            set field (Location_fk) ; $location

            go to original layout  // this will go back to the locations layout or no?

            set variable: $counter ; $counter + 1

            go to record/request [next;exit after last] // this doesn't seem to be moving to the next 1?

      end loop if [ $counter > $listLocation ]

       

      end loop

       

      Basically trying to create a new record on a different layout for every location record I have. Thanks

        • 1. Re: Trying to create records in another table
          Mike_Mitchell

          Ben_B94 wrote:


                go to original layout  // this will go back to the locations layout or no?

           

          No. It will go back to whatever layout you were on when the script fired off. You need to replace this with:

           

               Go to Layout [ Locations ]

           

          As an aside, you can make this a lot easier (avoid all the layout switching) by using a ListOf summary field to collect all the IDs into a variable and then looping over that. (You can also use one of a number of available Custom Functions to collect the IDs if you don't want to create a new field.)

           

          HTH


          Mike

          • 2. Re: Trying to create records in another table
            Ben_B94

            Thanks for the prompt reply Mike, changing that has sorted it.

             

            But just as a matter of interest when you say it will return to whatever layout when the script fired off my mistake is thinking that in this case the layout would be the locations one as I set it to go there before the loop? I thought when entering the loop i'm still on locations layout until I do the freeze window and switch to a different one?

            • 3. Re: Trying to create records in another table
              Mike_Mitchell

              Yep. Key phrase being, "until I switch to a different one." Go to Layout  does exactly that.

               

              The "original layout" is the layout on which the script starts, prior to any steps executing. It should be used carefully for that reason. If you can't predict what that layout will be (and you often can't), explicitly set the context.