4 Replies Latest reply on Aug 11, 2014 3:33 PM by duncanbaker

    Help with giving people a position number

    duncanbaker

      Hey folks

       

      I'm trying to work through an issue. I have a list of people records and I want the user to assign them numbers - the layout shows the list of people and there's a blank field next to each name to put the number. Consider it a top ten or starting order or whatever. In the end, it's not possible for two people to have the same number.

       

      So, the user adds numbers to the first 5 people in whatever order. There's a button named 'sort' (we'll come back to that but it runs a script, it's not just the main sort button) which resorts the records and shows him the list of names in number order (and any additional non-numbered names are under those in alphabetical order). If he decides that position number 5 should now be position number 2, he changes that number. Until 'sort' is hit, we now have two number 2's in the list. When 'sort' is hit, I am essentially looking at all the relevant records, sorting them by the assigned position number and then by modified timestamp (descending). Looks like this

      Name Position Modified

      Jon 1 5.19

      Tim 2 5.20 - this was number 5

      James 2 5.19

      Bob 3 5.19

      Andy 4 5.19

       

      I then loop through the records and reset the position number, starting at 1 and so on. Now the list looks like this:

      Name Position Modified

      Jon 1 5.19

      Tim 2 5.20 - this was number 5

      James 3 5.19

      Bob 4 5.19

      Andy 5 5.19

       

      This is fine. (I guess all the modified stamps would have updated too). BUT, if a user decides position number 2 should be position number 4, this is what we get after the sort by assigned number & modified:

      Name Position Modified

      Jon 1 5.19

      James 3 5.19

      Tim 4 5.20 - this was number 2

      Bob 4 5.19

      Andy 5 5.19

      When the reset of position numbers happens, Tim will be 3 not 4.

       

      I did have this happening on field exit per record, was grabbing the old number before it changed and then adjusting the modified sort order to ascending if the new number was greater than the old. But, that was proving too slow, so I want this all to happen on layout exit or when the 'sort' button is hit by the user. And multiple position numbers could be changed higher or lower prior to the user resorting the list with the button.

       

      Any ideas on how to accomplish this? I've thought about maybe grabbing the old position number and setting the value to a hidden field and possibly using this during the process but not figured out how yet. Needs to be FMGo compliant. There might be a completely different way to approach the whole thing, which I am open to.

       

      Thanks

        • 1. Re: Help with giving people a position number
          KylePutzier

          I simply put 2 buttons on my layout. 1 for up and 1 for down.

          The associated scripts check to see that a portal row (in my case) is selected and adds or subtracts .5 from a "SortOrder" field. The buttons also check to see if I am already at the top or bottom of the list and act accordingly. I then sort the list (after GTRR'ing to a special layout) and reserialize my SortOrder" field. When I exit the script, I leave the portal row selected so that the user can continuously click up or down untill the contact is in the position that they want. The user does not interact with, or even see, the "SortOrder" field, just the Up/Down buttons. My portal is sorted by the "SortOrder" field.

          I don't imagine this technique would work well if there are hundreds of contacts, but I usually have no more than 5 or 10. (I guess you could capture the Option key being pressed and jump by 5 or something.) I use the same technique anywhere I want a custom ordered portal.

           

          This is, basically, the same thing you are doing, I just reserialize my position field after every change.

           

          Kyle

          • 2. Re: Help with giving people a position number
            erolst

            The basic idea is that you subtract .5 from the new positional value if the new position is greater that the existing one, or add .5 if its smaller. Then you can simply resort and renumber using one sort order. For a single ad-hoc re-positioning this works fine with a $$var and three triggers (OnEnter, OnSave, OnExit [to clear the $$var])

             

            For a batch change that is triggered on command you could (as suspected) use a hidden field, applying the same logic as described above. Probably this could also be done with triggers and by maintaining a repeating variable that then is matched against the record number for a replace, followed by a resort and a re-numbering; but it may be a bit fragile …

            • 3. Re: Help with giving people a position number
              duncanbaker

              Thanks Kyle. Interesting but this list is likely to have say 50 names on it. The user is expected to assign a number to a name in a fairly random order so they need to find the person and type a number. Although this is more about editing the order of names than initial set up of them really.

              • 4. Re: Help with giving people a position number
                duncanbaker

                Thanks Erolst. The basic idea you outline (supported by Kyle's response) gives me some ideas to explore. I'll be back if it doesn't pan out ;-)