This is a public Forum  publicRSS

Forum post

    Guy Stevens
    Sorting field and Replace field contents in a portal.Answered
    Forum post posted February 2, 2012 by Guy Stevens, last edited February 9, 2012 
    96 Views, 3 Comments
    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)

    Screenshot:

    Best Answer

    PhilModJunk

    I'd freeze the window, then use go to related records to pull up the portal records on a layout based on the portal's table. Sort them by the sort number unless the relationship specifies the sort, then use replace field contents to renumber the records before returning to the original layout--where you'll see the renumbered records.

    Note: if it's possible that two or more users might be working with the same portal records, record edit locks caused by a user editing a portal record can keep replace field contents from updating the sort field.

    PS, you also don't need quotes around the 1,1 numbers...

    Answer

     

    • PhilModJunk

      I'd freeze the window, then use go to related records to pull up the portal records on a layout based on the portal's table. Sort them by the sort number unless the relationship specifies the sort, then use replace field contents to renumber the records before returning to the original layout--where you'll see the renumbered records.

      Note: if it's possible that two or more users might be working with the same portal records, record edit locks caused by a user editing a portal record can keep replace field contents from updating the sort field.

      PS, you also don't need quotes around the 1,1 numbers...

    • Guy Stevens

      Thanks PhilModJunk,

      Sounds like a great plan. I'll try this during the weekend and keep you updated.

      Guy

    • Guy Stevens

      Hey PhilmodJunk,

      That worked flawlesly.

      Well, not completely flawlesly because it took me couple of tries to get it to run completely perfect :)

      But your tips really did the trick.  ;)

       

      Thanks.