4 Replies Latest reply on Jun 4, 2013 3:23 AM by CG_1

    GetNthRecord - portal and with condition



      GetNthRecord - portal and with condition


           So, I have a layout (SHIFT) , with an unique id, with a portal (EQUIPMENT RECORDS).

           I have a button that triggers a script that fills the portal rows with the equipment's names, so that i can fill the rest with other information. Each equipment has several fields, including: KM1 (km that the machine ended up in the previous record), KM2 (km that the machine ended up at the end of the shift), KM (result from subtraction).

           So i would like to fill "km1" with the value "km" from the previous record, for THAT equipment.

           I've created a relationship with the equipments table to itself: KM1 = KM2, ID EQUIPMENT RECORDS dif ID EQUIPMENT RECORDS, and also EQUIPMENT = EQUIPMENT.

           I've based on a script i've found online and changed: "Get_From_last_Record::Company" to "Equipments:KM1" and "Name" to "KM2" ('cause it is the next field, after KM1)

           This only returns "?". Obviously, the script doesn''t have any mention to the equipment correspondence, but could retrieve any value... and it doesn't.

           Thanks in advance.


        • 1. Re: GetNthRecord - portal and with condition

               WIth the correct relationship, you don't need any script. An auto-enter field option can enter the value from the previous record for that equipment. The trick is in setting up the correct match fields and sort order for a new occurrence of your table. This would not match value by the km fields--they won't have matching values.

               A possible relationship is to match records by Equipment ID's and then to sort the related records in descending order by a date or time stamp field that auto-enters a creation

          • 2. Re: GetNthRecord - portal and with condition

                 So, I've changed the relationship to ID Equip = ID Equip and ID Shif dif ID Shift.

                 Sort order descending, both, through creation date field.

                 The KM1 field is a calculated value field, with If (Get ( RecordNumber ) - 1 = 0; 0; GetNthRecord ( KM2; Get ( RecordNumber) -1))

                 Am I going somewhere? It returns "0".


                 If I use GetNthRecord ( KM2; Get ( RecordNumber) -1), it returns the value not from a previous ID Shift and not from the correspondent equipment, but from the previous row, on the same shift.

            • 3. Re: GetNthRecord - portal and with condition

                   With a descending order specified as part of the relationship,

                   Try this reference to the related records

                   GetNthRecord ( RelatedTableOccurrencenamehere::KM12 ; 2 )

                   With that sort order and relationship, the first related record should be the same record, the next record, record number 2, should be the preceding record for that item of equipement.

                   Temporarily, set up a portal to that Tutorial: What are Table Occurrences? to make sure that the second portal row shows the record from which you need to copy data.

              • 4. Re: GetNthRecord - portal and with condition

                     It worked! I only had to change GetNthRecord ( RelatedTableOccurrencenamehere::KM2 ; 2 ) to GetNthRecord ( RelatedTableOccurrencenamehere::KM2 ; 1 ).

                Thank you so much