6 Replies Latest reply on May 28, 2014 8:36 AM by philmodjunk

    Portal updates sometimes

    nihmbrisby

      Title

      Portal updates sometimes

      Post

           Hello,

           I have a script that is fired from a table occurrence based on Invoices.  It creates a new invoice line item in a table joining invoices with contacts.  

           It seems to work fine.  In my layout based on the aforementioned table occurrence (itself based on Invoices), I have a portal looking into the join table.  After the script runs the new record is only sometimes (i'd say around 50%) displayed in the portal.  If it isn't, than clicking on the portal will cause it to update.  My script-

            

      Allow User Abort [ Off ]
      If [ Get ( ScriptParameter ) = "Transactions | Contact Popover | Affect Contact" ]
      Exit Script [ ] //This exits the script if/when it's triggered within itself
      End If
      Set Field [ Transactions::__Nonglobalsearch; "" ] //This clears my search field (which filters the portal of all contacts and which I no longer use a global for (hence the name)
      Commit Records/Requests [ No dialog ]
      If [ not IsEmpty ( Get ( ScriptParameter ) ) or not IsEmpty ( Transactions::_fkContactsIDGlobal) ] //The script parameter is for if they clicked on the portal to select a contact.  Transactions::fkContactsIDGlobal is if they create a new contact.  It's used in a relationship between Invoices and Contacts which allows for creation of records in Contacts
      Freeze Window

      //These next steps take the primary keys (INVoices and COntacts) to a new record in the join table

      Set Variable [ $CONTACTS_ID_TRANSACTIONS; Value:If ( not IsEmpty ( Get ( ScriptParameter ) ) ; Get ( ScriptParameter ) ; Transactions::_fkContactsIDGlobal) ]
      Set Variable [ $TRANSACTION_ID_CONTACTS; Value:Transactions::__pkTransactionsID ]
      Go to Layout [ “Utility_Contacts_Transactions” (join_Contacts_Transactions) ]
      New Record/Request
      Set Field [ join_Contacts_Transactions::_fkContactsID; $CONTACTS_ID_TRANSACTIONS ]
      Set Field [ join_Contacts_Transactions::_fkTransactionsID; $TRANSACTION_ID_CONTACTS ]
      Go to Layout [ original layout ]
      Else
      Go to Object [ Object Name: "Select Contact Panel" ]//This branch happens if they select 'new contact' but don't enter anything
      End If
      Set Field [ Transactions::_fkContactsIDGlobal; "" ]
      Commit Records/Requests [ No dialog ]

            

           PS If the user has created a new contact, the portal always refreshes.  It's only when the script fires from the button that's overlaying the portal from which the user can pick a contact.

        • 1. Re: Portal updates sometimes
          nihmbrisby

               So I've 'solved' the problem, but I'm not exactly sure why.  The fourth step was the problem: 

          Set Field [ Transactions::__Nonglobalsearch; "" ]

               If I disable it, or even just move that it the bottom (right above:

                Set Field [ Transactions::_fkContactsIDGlobal; "" ]

               Then the portal refreshes every time.  Nonglobalserach is the 'search' field for the list of all contacts.  It's used to filter a cartesian join between Transactions and Contacts.  Per a bunch of my earlier posts, I'd done a ton of reading on how best to handle this, and finally decided on using a non-global field that I make sure and clear after the user's done his or her search.

               So non-global search is no doubt linked to the list the user selects from (which was why I thought to disable it).  But if anyone could give me any more detail that might help avoid similar mistakes in the future I'd greatly appreciate it.

          • 2. Re: Portal updates sometimes
            philmodjunk

                 Will your portal show all contacts if the search field is empty or no contacts?

            • 3. Re: Portal updates sometimes
              nihmbrisby

                   The portal I search from shows all contacts if the search field is empty.  The portal looking into the table occurrence that joins invoices and contacts shows no records if there are not (and shows the correct records when the exist- really the only manifest issue was the refresh thing when this line is near the top:Set Field [ Transactions::__Nonglobalsearch; "" ]

              • 4. Re: Portal updates sometimes
                philmodjunk

                     Is there one portal or two? Is there one portal from which you select a contact by clicking and another that displays the new record you created by selecting a contact?

                • 5. Re: Portal updates sometimes
                  nihmbrisby

                       Sorry for not being more clear- there are in fact 2 portals.  This is an invoice layout.  An invoice can have many contacts, and a contact many invoices. This many to many is thus bridged by a join table (join_Contacts_Invoices).  On this invoice layout, the user will select from a list of all contacts.  This list is a portal into a new table occurrence (cartesian_Contacts) which is a cartesian relationship.  This portal is filtered using patterncount.  The pattern tested for is what the user inputs into the search box above the portal (which is a regular field in the invoice table- thanks for your help in the other thread which helped me decide on this).  The portal row is overlaid with a button to grab the primary key and then- well i just run standard script to create a new join record with the Conact pk and the Invoice pk

                       So that's the first portal.  The second portal simply looks into the join table.  It displays all related join records.  This portal was the one with the weird updating issue that was solved by moving Set Field [ Transactions::__Nonglobalsearch; "" ] to the end of the script.  "Nonglobalsearch' is what filters the first portal i described.

                       I'm new to filemaker, but I've had enough experience 'coding' (in a very different scenario) to know that 'solutions' you don't understand tend to come back to haunt you.  

                       As always, your help is greatly appreciated.  With your help I'm almost at the point where I feel like I've gotten a really sufficient handle on all I need for my solution.

                  • 6. Re: Portal updates sometimes
                    philmodjunk

                         That was my original assumption here, but what has me scratching my head in puzzlement is that the script step in question:

                         

                              Set Field [ Transactions::__Nonglobalsearch; "" ]

                         Modifies a field that, as far as I can tell from here, should have no effect whatsoever on what data does or does not appear in the second portal--the portal to the join table. This shouldn't be a filtered portal as far as I can tell, so I don't see how the value assigned to this field should make any difference here.

                         The only thing that I can think of is that putting this at the end triggers a window refresh that may incidentally update the join table. But I don't see why the commit records step at the end of the script doesn't produce the same result...