4 Replies Latest reply on May 6, 2015 12:37 PM by BarryYarkoni

    Renumber a found set in sorted order

    BarryYarkoni

      Title

      Renumber a found set in sorted order

      Post

      Disclaimer: FMP Newbie

      I have a found set from the table "EquipmentUsage" with a field called UsageOrder.  This is a manually entered field where the user can specify the display order in a portal.  To change the display order, the user can change 4 to 2.5 and the portal will immediately change the display order.  I wrote a script assigned to a "Renumber" button which sorts and renumbers the found set to change everything back to a integer list as follows:  (dating myself here - anybody remember the old "Edit Renumber" in BASIC?)

      Find Matching Records [Replace; EquipmentUsage::ContentID]
      Sort Records by Field [Ascending; EquipmentUsage::UsageOrder]
      Replace Field Contents [No dialog; EquipmentUsage::UsageOrder; Serial numbers]

      What is happening is that the found records are being renumbered, but in their entry order, not the Sort Order.  So I tried this modification.  Created another field name TempOrder:

      Find Matching Records [Replace; EquipmentUsage::ContentID]
      Sort Records by Field [Ascending; EquipmentUsage::UsageOrder]
      Replace Field Contents [No dialog; EquipmentUsage::TempOrder; Serial numbers]

      Same result.  Any suggestions on how to get it to assign serial numbers to the found set by the sort order??

      Many thanks.
      Barry

       

        • 1. Re: Renumber a found set in sorted order
          philmodjunk

          The second script should work. I suggest putting a pause after the sort records so that you can check and see what order you are actually getting. Perhaps you are sorting on the wrong field or the field is text when it should be number (Though then, I'd expect to see your portal fail to sort records correctly.) And perhaps your current layout is not based on the table "EquipmentUsage"? That would also cause this to fail.

          • 2. Re: Renumber a found set in sorted order
            BarryYarkoni

            The current layout is based on a parent table (Content) and EquipmentUsage is a child table linked by ContentID displayed in a portal in the layout.  One record in Content is selected, and the correct records are displaying in the portal, and the serial numbering is being done on those records, but apparently, the Sort Records step is not controlling the order of the serial numbering.  The second version was just to create a second field to make it easier to see what's happening.  Both UsageOrder and TempOrder are numeric.

            • 3. Re: Renumber a found set in sorted order
              philmodjunk

              Which explains the problem as you are on the wrong layout for your script.

              You aren't finding EquipmentUsage Records with your find matching records step. You are finding Content records. The same goes for your sort, it sorts Content records not EquipmentUsage records.

              Try it this way:

              Go To Related Record [Show only related records; From table: EquipmentUsage; Using layout: "EquipmentUsage" (EquipmentUsage) ]
              Sort Records
              Replace Field Contents
              Go to Layout [Original Layout]

              • 4. Re: Renumber a found set in sorted order
                BarryYarkoni

                Many thanks!  This worked.

                Barry