6 Replies Latest reply on Feb 26, 2009 9:00 AM by ninja

    How to write a Script that duplicates a record in a different layout

    emcclure

      Title

      How to write a Script that duplicates a record in a different layout

      Post

      Hello,

       

      So I'm really new at the Script writing part of all this. And it may sound kind of weird when I try to describe what I'm trying to do but please bear with me. I current have a table named "New Hire" and one named "Employee." What I'm trying to do is write a script that willtake the New Hire Record and create that record in the Employee table once the Start Date field is greater than the current date field. Is there any way I can do this?

       

      Please help!

        • 1. Re: How to write a Script that duplicates a record in a different layout
          ninja
            

          Howdy emcclure,

          Thanks for the post and welcome to the forum!

           

          The script can go a few ways, one including lookups (that I find dangerous so I won't explain that one) and the long, rugged way.  The longer but rugged way is this:

           

          GoToLayout [Employee]

          New record/Request

          SetField [Employee::Field1;NewHire::Field1]

          SetField [Employee::Field2;NewHire::Field2]

          SetField [Employee::Field3;NewHire::Field3]

          SetField [Employee::Field4;NewHire::Field4] ...

          GoToLayout [NewHire] {maybe can be GoToLayout [original]}

          Delete Record

          GoToLayout [ThePlaceYouWantToEndUp]

           

          If you have over 20 fields to copy over to the other table...you might also consider using the "Import Record" function as well.  I tend not to use Import Record, but it would work well for what you are trying to do...it's a preference thing with me.  If you only have 5-10 feilds...keep it simple so the next guy after you can figure it out.

           

          Let us know how you progress!

          • 2. Re: How to write a Script that duplicates a record in a different layout
            emcclure
               Okay. So I'm trying to do the script but I'm having a problem on the SetField part. It will only let me specify one field. Ok, so let me give you the full story of what I want to do. When someone goes into my New Hire layout, I would like for the record to be moved/duplicated as an Employee record IF the start date is past the date that its being viewed (current date). Once moved/duplicated I would like for the New Hire record to be Omitted. Im going to be using the New Hire table to pull info into the Employee layout so the record cannot be deleted. Does this make sense?
            • 3. Re: How to write a Script that duplicates a record in a different layout
              ninja
                

              Howdy emcclure,

               

              Yes, it makes sense.   That's what the script above does with the exception of the date check.

               

              (check to make sure start date is past current date)

              If(NewHire::StartDate>Get(CurrentDate))

               

              (Then create a blank record in the Employee table)

              GoToLayout [Employee]

              New Record/Request

               

              (Then copy the fileds over one at a time.  You'll have to do it once per field you want to copy over.  In Setfield, you would select the target field, and then the calculated value which would be equal to the source field from your NewHire Table)

              SetField [Employee::Field1 ; Newhire::Field1]

               

              (If you want the record out of the NewHire Table, if not...skip this step)

              GoToLayout [NewHire]

              Delete Record

               

              Again, if you have just a few fields...this way would be my preferred way.  Essentially you'll mirror your NewHire record into the Employee Table, then kill the NewHire record.  If you have 65 fields, you will probably want to look at Import Record.

               

              BTW,  Why not just have one table for the information and use a "Status" field to differentiate between "NewHire" and "Current Employee" ?  This status filed could be a calculation field that looks at the current date and hire date and automatically declare the employees' status?  Wouldn't that be easier than moving entire records around?

               

              Just a thought...

              • 4. Re: How to write a Script that duplicates a record in a different layout
                emcclure
                  

                Hi Ninja,

                 

                I tried to do your script and I'm pretty sure it would have worked. The only thing is I setup a layout script trigger to do the script and now :womanvery-happy:I've frozen the entire database, well it keeps loading. I have to force quit it to get out of it and then recover the file, which then just does the same thing all over again. How can I stop this? Please help!:womansad:

                • 5. Re: How to write a Script that duplicates a record in a different layout
                  emcclure
                    

                  Hahahahaha!!!!!

                  Well I figured out how to get it unfroze. I have 17,000 blank records added to my Employee Layout. So I think I'm leaning more towards just changing the status by calculation. Can you explain that in more detail. 

                   

                  Thanks!

                  • 6. Re: How to write a Script that duplicates a record in a different layout
                    ninja
                      

                    Wow, My script didn't even have a loop feature in it...you're really good!

                     

                    On your Employee table, you would place a field called "Status".  The Status field is a calculation field whose result is Text.

                     

                    If(HireDate < Get(CurrentDate) ; "Current" ; "Pending" )

                     

                    Now when you work in this table, work within found sets for 'Status = Pending' or 'Status = Current'.  you could also put buttons on the layout which perform the finds for "current", "pending" or "show all".

                    The button you used to hit to switch layouts to the "pending" table, now stays on the current layout (or goes to another) AND performs a find for "pending" in the Status Field.

                     

                    Did I explain it well, or talk around in circles...?