11 Replies Latest reply on Jul 16, 2010 5:53 PM by hjgunn@mmedia.is

    Inserting Line in Portal

    m3m3m3

      Title

      Inserting Line in Portal

      Post

      I know there's a function to delete a line in a portal, but is there one to insert a line above another one?

      The full problem is this:  I have a  database for making proposals to send out to clients.  Once the proposal is accepted, I have a button that generates an Invoice (basically copies all the information that was in the Proposal but adds in billing information).  Many times there adjustments that need to be made (some clients don't use some materials, they need some prices to be changed for the project to fit in the budget etc.)  I can make those easily and delete lines.  However, there are sometimes where other items need to be added into the invoice in a specific spot (unexpected rentals or materials or personnel need to be grouped with similar items).  Is there a way to do this?

      Screen_shot_2010-07-14_at_11.57.25_AM.jpg

        • 1. Re: Inserting Line in Portal
          bcooney

          Add a sort order field in the portal's table. Then just sort the line items by this field. You are printing Invoices from the line items table, not printing the portal, right?

          • 2. Re: Inserting Line in Portal
            philmodjunk

            You can script such a operation. We do that with one of our invoicing systems to support a unique customer need. Add a serial number field to your portal record table if you do not already have one. Sort your portal records on this serial number. Since the serial numbers will be assigned in increasing order, this will keep the rows sorted in creation order unless you change the serial number field's value to insert it higher into the list of records displayed in the portal.

            The following script inserts a new blank record immediately below the record where you clicked the insert button. It will insert up to 10 new lines before it fails. You can modify the script to insert more lines by using a smaller increment.

            If [ Right ( PortalTable::SerialNumberField ; 1 ) = "9" ]
               Show Custom Dialog ["Can't insert another row here..."]
            Else
              Set Variable [$ID ; Value: ParentTable::ID] //capture whatever field value links the parent record to the portal records
              Set Variable [$Serial ; Value: PortalTable::SerialNumberField]
              Freeze Window
              Go To layout [PortalRecords//any layout based on the portal record's table will do]
              New Record/Request
              Set Field [ PortalTable::ID ; $ID ] //give the record the value it needs so it appears in the table
              Set Field [ Portaltable::SerialNumberField ; $Serial + 0.1]
              Go To Layout [original layout]
            End If

            • 3. Re: Inserting Line in Portal
              m3m3m3

              @bcooney  I'm printing from the line items, not the portal.

              @PhilMod - I tried the script you posted (filled in the correct fields for my database) and assigned it to a button and now it's creating a new record for a new Proposal.   

              • 4. Re: Inserting Line in Portal
                m3m3m3

                Would it be more helpful for me to put up another screenshot from my database or supply more information about it (related tables, layouts, relationships, etc...)?

                • 5. Re: Inserting Line in Portal
                  philmodjunk

                  "I tried the script you posted (filled in the correct fields for my database) and assigned it to a button and now it's creating a new record for a new Proposal.   "

                  Sounds like your script isn't switching to a layout based on the portal's table or records as specified in line 7 of my script. If, instead, you are on your "proposal" table when the New Record/Request step executes, you indeed will get a new proposal record instead of a new portal record.

                  • 6. Re: Inserting Line in Portal
                    hjgunn@mmedia.is

                    Usually when doing this I open a separate window for the process. I added a few lines to Phil's script.

                    If you like, you could even open it off screen by positioning it at -10000,-10000

                    Hans

                    If [ Right ( PortalTable::SerialNumberField ; 1 ) = "9" ]
                       Show Custom Dialog ["Can't insert another row here..."]
                    Else
                      Set Variable [$ID ; Value: ParentTable::ID] //capture whatever field value links the parent record to the portal records
                      Set Variable [$Serial ; Value: PortalTable::SerialNumberField]
                      Freeze Window

                      Select window "Add record"

                      If error is not 0

                        Open new window "Add record"

                          Go To layout [PortalRecords//any layout based on the portal record's table will do] 

                        End IF

                      New Record/Request
                      Set Field [ PortalTable::ID ; $ID ] //give the record the value it needs so it appears in the table
                      Set Field [ Portaltable::SerialNumberField ; $Serial + 0.1]
                      Close window "Add record"
                    End If

                    • 7. Re: Inserting Line in Portal
                      philmodjunk

                      While using a different window works, it really isn't necessary to do this unless you need to preserve the current found set/current record/ current sort order for the Portal records layout. (And those don't affect what you see on your proposals layout in any way.)

                      • 8. Re: Inserting Line in Portal
                        m3m3m3

                        @Hans - I'm trying to keep everything in one window

                        @PhilModJunk - Do you think the problem could be because I have the Proposal and Invoice in the same layout - they're just on separate tabs...

                        • 9. Re: Inserting Line in Portal
                          Steve Wright

                          Sorry to jump in here with something completely different..

                          I required the same ability, but instead of inserting rows at a specific position I used the following technique to allow the user to re-arrange the rows using drag and drop  http://excelisys.com/web/downloads/index.php

                          There are a few posts about it here too : sorting portal rows with drag and drop functionality

                          • 10. Re: Inserting Line in Portal
                            philmodjunk

                            To repeat, the script must switch to a different layout that refers to the table that stores the records shown in the portal. It will not work if you don't switch layouts, create the new record, adjust the serial and switch back.

                            • 11. Re: Inserting Line in Portal
                              hjgunn@mmedia.is

                              "I'm trying to keep everything in one window"

                              This was my thought as well, in the early days of post FM 7, but then I found out that it was "simpler" to stay within context by opening a new window, every time the context changed, than to change the contents of the already existing window. Also by opening the new windows "off screen" you get very little flicker if any.

                              By doing everything in the same window, if your script crashes for some reason, changing the contents of the original window could leave your user in a state of limbo, forcing him to restart the solution to get back to his point of origin.

                              By using one window for each context you run the danger of leaving some off screen windows open if your script crashes, but so what? No one will notice it anyway and they will be closed the next time you run the script, since the script always checks if the window is already open and only creates it if it is not.

                              My scripts are built of sections where each section is built around a context and does something to that context. Makes everything a bit easier to read. For example, I have a script that creates and sends out invoices, printed on paper and as PDFs. It contains 9 Sections and one of the sections contains a loop and within that loop I have 5 segments. The script changes context 12 or so times and by using a new "off screen" window each time the context changes the user actually doesn't notice that anything is going on at all. Of all those windows used only 2 are visible to the user since they ask for data input.

                              Doing everything in the same window would have been a bit muddled to say the least

                              Since I started using this method I hardly ever change the contents of a window that is already open and my users have stopped complaining about being left "hanging".

                              Just my thoughts...

                              Hans