3 Replies Latest reply on Feb 4, 2012 2:55 PM by GuyStevens

    Sorting field and Replace field contents in a portal.

    GuyStevens

      Title

      Sorting field and Replace field contents in a portal.

      Post

      Hey you guys,

      I've run into a little problem that I can't seem to figure out.

      I made a layout with two portals and it works great. You select a category in the first portal, that sets a field on the layout which filters the second portal based on a relationship to the field on the layout.

      In this second portal I have Articles with a Sort number. Next to the sort numbers I have up and down buttons to move the item one spot up or down in the sort order. And my portal is sorted by that number.

      The problem with this is that if you sort everything and give it numbers (1, 2, 3, ...) it's annotng to add something in the middle because then you have two items with the same sort number. And you have to manually change all the numbers that follow.

      No I learned about the fact that you can use "Replace Field Contents" to replace the contents of that Sort field within a found set to a serialized number.

      So I made my script:

      If[Get (ScriptParameter) = "Up"]
         Set Variable[$Sorteernummer; Value:TblWinkellijstDetail_Artikels Winkellijst::Sorteernummer + "1,1"]
         Set Field[TblWinkellijstDetail_Artikels Winkellijst::Sorteernummer; $Sorteernummer]
         Commit Records/Requests[No dialog]
      End If
      If[Get (ScriptParameter) = "Down"]
         Set Variable[$Sorteernummer; Value:TblWinkellijstDetail_Artikels Winkellijst::Sorteernummer - "1,1"]
         Set Field[TblWinkellijstDetail_Artikels Winkellijst::Sorteernummer; $Sorteernummer]
         Commit Records/Requests[No dialog]
      End If
      Replace Field Contents[TblWinkellijstDetail_Artikels Winkellijst::Sorteernummer; Replace with serial numbers:Custom values; Initial value:1;Increment value:1][No dialog]

      (Sorry for the dutch names)

      What happens is:

      - If the up button gets pushed a variable is created of the "Sortnumber" +1.1
      I used 1.1 so it would always move one record up or down. Otherwise the sort number becomes the same as the nest records sort number and the order of your fields doesn't change.

      - That new sortnumber then gets set into the "Sortnumber" field.
      - That record is commited
      - The portal resorts

      That record then moves one step up because the portal sorted on this "Sort Number"

      Because of the 1,1 my sort number looks a bit ugly because now you have a line that looks like: 1, 2, 3, 4.9, 5, 7, ...

      Therefore I wanted to use "Replace Field Contents" but when I do that my records get put back into their old position. It's like the sort number hasn't been comitted even tough there is a commit script step. Or as if the portal sorting isn't enough.

      If I try this in a table it works fine.

      I can change a sort number en then the replace field contents step perefctly reserializes all my sort numbers into their new order.

      I think my problem might lie in the fact that I'm working in a portal. This portal is also based on a second TO of a table. I don't know if that might have something to do with it.

      Anyone have any clues? (I attached a screenshot to give you a feel of the layout)

      Portals.png