1 2 Previous Next 16 Replies Latest reply on May 7, 2017 6:32 AM by PeterCortiel

    Inserting and adjusting lines in a portal

    JoeSand

      Questions similar to this have been asked before, all that I have seen have been rather old.  I'm hoping that FM15 offers more elegant options:

       

      I'm creating a solution for estimating and invoicing automotive repairs.  The most effective way I've found to display these things in via a portal of "line items" within the "estimate", or "invoice" layout, although I'm not married to this scheme if there is a better option.

       

      Basically, I need flexibility to add, delete, and move line items within the portal.  Adding lines to the bottom isn't a problem, and neither is deleting, but an elegant solution to insert or re-position lines is evading me.

      I've created a serial number to sort by (a number) and my thought is that, if I determine the difference between serial numbers of sequential portal rows, divide it by two, and use this as the serial number of the new entry, it will be positioned correctly, and since the serial number can be divided infinitely, there's no practical limitation to how many times this could be done.  Something similar could be done to slide rows up and down within the portal.

      Sounds easy, but I haven't figured out how to do these calculations using data from different portal rows.  Anyone been down this road?

        • 1. Re: Inserting and adjusting lines in a portal
          keywords

          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.

          • 2. Re: Inserting and adjusting lines in a portal
            philmodjunk

            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.

            • 3. Re: Inserting and adjusting lines in a portal
              JoeSand

              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?

              • 4. Re: Inserting and adjusting lines in a portal
                philmodjunk

                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

                       ) //let

                 

                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.

                • 5. Re: Inserting and adjusting lines in a portal
                  JoeSand

                  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...

                  • 6. Re: Inserting and adjusting lines in a portal
                    JoeSand

                    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)

                    • 7. Re: Inserting and adjusting lines in a portal
                      rgordon

                      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).

                      • 8. Re: Inserting and adjusting lines in a portal
                        BruceRobertson

                        Test before saying such things.

                        Before testing; don't say anything.

                        • 9. Re: Inserting and adjusting lines in a portal
                          philmodjunk

                          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.

                          • 10. Re: Inserting and adjusting lines in a portal
                            JoeSand

                            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...

                            • 11. Re: Inserting and adjusting lines in a portal
                              philmodjunk

                              "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.

                              • 12. Re: Inserting and adjusting lines in a portal
                                BruceRobertson

                                Regarding get( recordNumber ) vs get( activePortalRowNumber))

                                Screen Shot 2017-03-17 at 10.18.04 AM.png

                                • 13. Re: Inserting and adjusting lines in a portal
                                  philmodjunk

                                  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.

                                  • 14. Re: Inserting and adjusting lines in a portal
                                    JoeSand

                                    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? 

                                    1 2 Previous Next