Sounds like you just need a sort field, which can be a simple number, and then set your portal to sort by that field. If you want to move a portal row to a new spot in the portal all you would need to do is alter it's sort number to suit where you want it to land. The actual sort numbers have no meaning other than sorting, and can be fractions to avoid having to mess with numbers of other records.
GetNthRecord can be used to access the value of another portal record's serial number.
Let ( R = Get ( RecordNumber ) ;
If ( R > 1 ; GetNthRecord ( serialNumberField ; R - 1 ) ) )
will return serial number of the preceding portal record. You can simplify your math if you simply add the two values and divide by two.
So, this record number adjusts for the unique sort order within a portal, or do I need to use a "line items" layout with the same sort order used in the portal?
IT should work right in the sorted portal.
I was answering by iPhone earlier, here's the full up expression that you might use in a set field script step to move a portal record up one line when the portal is sorted by SerialNumberField.
Let ( [R = Get ( RecordNumber ) ;
PrevSerial = If ( R > 1 ; GetNthRecord ( PortalTO::serialNumberField ; R - 1 ) )
(PortalTO::SerialNumberField + PrevSerial ) / 2
You may need a commit records before the portal rows update to their new positions. I sometimes add a script that pulls up this found set, sorts and uses replace field contents to renumber them in perfect order just to "clean up" the values, but this isn't really needed if you don't actually display this field in the portal.
I'll test this out and make sure it works, but it looks like exactly what I was looking for. I didn't understand how record numbers worded with portals.
I'll report back...
I just tried a couple things to see if I understand how the RecordNumber function works, and it's not doing what I expect. I created a number field in the Line Item list that displays in the portal row, and a script that sets this field to the record number on field entry. This field gets set to the record number of the layout, not the portal, regardless of which row I'm in. The same thing works fine if I use a "line item" layout sorted like the portal.
Am I doing something wrong, or is there a way to change the context for the Set function (presuming that's the problem)
Get(recordnumber) doesn't work in A portal. It returns the record number of the record you are in, not the portal row. I believe you need to use Get(activeportalrownumber).
Test before saying such things.
Before testing; don't say anything.
rgordon is correct. I was suggesting this from something that I did several years ago and you need to use get ( activePortalRow ). But more changes than that are needed.
I ended up using this calculation in a test that I just ran:
Let ( [ R = Get ( ActivePortalRowNumber ) ;
PrevSerial1 = If ( R > 2 ; GetNthRecord ( Child::SortField ; R - 2 ) ) ;
PrevSerial2 = If ( R > 1 ; GetNthRecord ( Child::SortField ; R - 1 ) ) ];
If ( R > 1 ; ( PrevSerial1 + PrevSerial2 ) / 2 ; PortalTO::SortField )
And I needed to follow that with Commit Records so that the row automatically moved up a row.
MovablePortalRows.fmp12.zip 68.5 K
Yeah, I've figured that out, and I've been playing with ways to insert a new line into a portal besides entering data at the bottom of the list. I don't see a way to script the addition of a new record without first moving to a Line Items layout.
I'm beginning to think I'm going to be chasing my tail trying to achieve these things in a portal rather than making my main data entry layout a Line Item layout rather than an Invoice (or Repair Order, in my case) layout. Unfortunately simplifying one thing complicates others...
"I don't see a way to script the addition of a new record without first moving to a Line Items layout."
The script that goes to another layout can first open a window hidden off the edge of the monitor so as to leave the visible window undisturbed.
But there are two other methods for adding a related record:
1) You can use go to object followed by go to portal row to put the focus on the last portal row before using set field to create a new portal record. This is not how I like to do it but works.
2) Use a method known as MagicKey to create your related records. You can web search this term to find some good articles on how to do it. The beauty of MagicKey is that you don't have to change layouts or portal rows to add records.
Yes, but when I TESTED it, the script failed to evaluate Get ( RecordNumber ) correctly and that's where there's a misunderstanding here. As a calculation in a field, it works, as a step in a script, it returns the record number of the parent.
Actually, I first tried it as a calculation, and it didn't work. It returned nonsense... the first row was "1" and the rest were blank. I didn't use the Case function, but would that make a difference?