1 Reply Latest reply on Aug 16, 2014 9:14 AM by philmodjunk

    Create 6 Line-Items at once



      Create 6 Line-Items at once


           I have a table with PERSONS that is connected with a table FINANCES.

           On a PERSONS-layout i have a portal through which i can create FINANCE-records.

           Tables are connected through a PersonID-field.

           Every month there are like 100 people who start. Two months after someone starts we get some money from the government, let's say: 60 euro's. When i point the 60 euro's to someone it should be divided into 6 FINANCE-records.

           - record 1: month of start: 10 euro

           - record 2: month of start + 1: 10 euro

           - ...

           - record 6: month of start + 5: 10 euro

           Is it possible to create a script that automatically creates 6 FINANCE-records (portal-records on the PERSONS-layout) for all the people that start in certain month. This would save me a lot of time.

           Can somebody help me please?


        • 1. Re: Create 6 Line-Items at once

               Let's say that you have this relationship:

               Persons::__pkPersonID = Finances::_fkPersonID

               Add a number field, gAmount and give it global storage.

               Then this script will generate the 6 related records in Finances:

               Set Variable [$ID ; value: Persons::__pkPersonID ]
               Go to Layout ["Finances" (Finances) ]
                  Set Variable [$K ; value: $K + 1 ]
                  Exit Loop If [$K > 6 ]
                  New Record/Request
                  Set Field [Finances::Amt ; Round ( Persons::gAmount / 6 ; 2 ) ]
               End Loop
               Set Field [Finances::Amt ; Persons::gAmount - 6 * Round ( Persons::gAmount / 6 ; 2 ) ]
               Go To layout [ Original Layout ]

               There's no part of this script that assigns a "month" value as it is not clear to me how you need to handle that info and how it is stored in your table. This could be a number field for the month of the year or it could be a date with the date for the first day of the specified month. The months could be calculated from the current date or from a value entered into a global field as shown here for the amount.

               Note: that last set field step adjusts the final record for any round off error that may occur when you divide an amount by six and round the resulting value. This may make the final entry a small fraction of a Euro larger than the other to account for this.