0 Replies Latest reply on Aug 14, 2014 11:17 AM by jetserkok

    Script to duplicate / split records

    jetserkok

      Title

      Script to duplicate / split records

      Post

           Hi all, 

           I'm am not very familiar with scripting, so needs some help to create a script. For simplicity sake lets say i have two tables. 

           Table A: ClientOrder table: with rows/records of garments ordered in various sizes. 
           Table B: The table i wish to copy and split one record from Table A into multiple to Table B.  

           There is a one to many relationship between A and B. One ClientOrder row can have many rows in table B. One row in the ClientOrder table, please see example attached, can have various sizes with quantities. To keep things simple, lets say that one row in Table A can be:

      1 row
           orderid: 1
           garment: X,
           size S: 1 (ordered once)
           size M: 3 (ordered three times)
           Size L: 2 (ordered twice)
           Size XL: 2  (ordered three times)
           Total price: 800$ (each garment is 100$)

      The script needs to do this: 
           This one row in Table A needs to be split based on a fixed 'amount' into multiple rows that need to automatically filled into Table B, when clicking on a button 'create records' for example. 

           Lets say the fixed amount is 350. In that case, the above row (in Table A) should result into 3 rows in Table B. 1 garment equals 100$ in example, so in the first 350 only 3 garments fit, in the second also 3 garments and in the third row only 2 garments are left. This should result in: 

      Row 1
           table B ID: 1
           orderid: 1
           garment: X
           size S: 1
           size M: 2
           size L: 0
           size XL: 0

      Row 2
           table B ID: 2
           orderid: 1
           garment: X
           size S: 0
           size M: 1
           size L: 2
           size XL: 0

      Row 3
           table B ID: 2
           orderid: 1
           garment: X
           size S: 0
           size M: 0
           size L: 0
           size XL: 2

           In fact, even better would be if the script can do this for multiple records in Table A at the same time, based on the OrderID in Table A. So when entering an orderID, multiple records in A are being split into multiple records in Table B. 

           Its kind of complicated... hopefully somebody will be able to help me. 

           Many thanks!

            

      Screen_Shot_2014-08-14_at_13.36.28.png