1 2 Previous Next 22 Replies Latest reply on Apr 13, 2016 2:09 PM by user26728

    setfield works on first row in portal, but not the other rows

    user26728

      Hello.  Anybody have an idea what would cause this behavior?

       

      I have a layout with a portal. (this is a FM 14 file)

      It's setup to run a script when a value is changed in a field in the portal.

      The script sets the fields in the portal row and then copies the values to a record in another table.

      The problem I am having , happens when you do the same thing in the next row of the portal.

      The script is triggered, but doesn't copy the values to the other table..

      The weird thing is, If I delete all the records in the second table and run the script again, it works. But only the first time with the first row of the portal.

       

      I would really appreciate any ideas  about this that someone could give me... Thanks!

        • 1. Re: setfield works on first row in portal, but not the other rows
          JesseH

          Post your script so people could have a look and give a better answer to what the problem might be

          • 2. Re: setfield works on first row in portal, but not the other rows
            bigtom

            I am assuming you are using some way to track the portal row the change was made and using an object name for the field.

             

            Without seeing the script or the file is it hard to tell what is going on or how to fix it. Screenshot of the script?

            • 3. Re: setfield works on first row in portal, but not the other rows
              user26728

              Here's the script..

              Really simple. put a number in the quantity field in the portal.

              Triggers the script.

              Data is copied to a record in the Delivery Items table which has already

              been created.

              It always works on the first row of the portal.

              Then not on any of the other rows...

              thanks.

               

              greg

              • 4. Re: setfield works on first row in portal, but not the other rows
                ch0c0halic

                If you were going to do this manually would you just start typing? No, you'd click into the correct field in the correct portal row! You have to write the script to tell FMP exactly what to do so it performs (mostly) the same operations you would do manually.

                 

                You have set the 'context' of what you want FMP to do. You do this by first entering the correct portal, row, and field so FMP know where (which record) its supposed to be processing.

                 

                Without setting up the context of the portal your script is always telling the first related record of the relationship. There is no portal context so there is no portal row so there is no setting the correct related record.

                 

                Start out by first using a Go to field, where the field you want to go to is displayed in the portal. This establishes that your context is the portal, the related records as defined by the portal relationship.

                Next go to the specific portal row you want to set fields for. This specifies which related record you want to write to.

                The you can use the set fields. This writes data to the related record as specified by the portal row in the context of the portal relationship.

                 

                If you were also running a subscript that goes to another layout you'd also have to keep track of which portal row you were last in. When you switch layouts you exit the current record, and portal, so all layout context must be reestablished when returning to the layout. FMP always behaves this way. Try it manually and see what happens.

                 

                Pseudo script

                 

                go to field ["Delivery Items Create::Date"] // must be in the portal you wish to use

                go to portal row ["1"]

                Loop

                set field ["Delivery Items Create::Date" ; "deliveries::date"]

                Set field ...

                Set field ...

                Go to portal row ["Next" ;  "Exit After Last"]

                End loop

                 

                 

                 

                If you had a perform script instead of the set fields you'd add this before the Perform Script []

                Set variable ["$my_row" ; "$my_row + 1"] //establish desired portal row context for subscript

                and after returning from the script

                go to portal row ["$my_row"]//establish desired portal row context for Go to next Row

                 

                I hope this makes sense. I wrote it off the top of my head so it may not work at first attempt. This lays the basic foundation for scripting in FMP. First do it manually. Write down every step you take. Then write a script to do it the FMP way.

                • 5. Re: setfield works on first row in portal, but not the other rows
                  bigtom

                  I believe the previous example is not what you are looking for exactly as it loops through an entire portal and does not just work with the changes made to a single portal row.

                   

                  Your script is obviously not working because there is no context. Using an object name on the field in the portal is pretty effective, but not necessary. Why is the data copied? How are the tables related?

                   

                  Screen shot of your graph?

                   

                  The more info you share the better and quicker response you will get.

                  • 6. Re: setfield works on first row in portal, but not the other rows
                    user26728

                    to all , thanks for looking at this.. sorry If I'm not clear about what's

                    going on..

                    to answer a few questions, the context of the script is from the portal.

                    user clicks on the quantity field in the portal, enters a number and the

                    script fires.

                    It doesn't take you anywhere else, just copies the values in the  fields in

                    the active portal row. Then pastes them into the record in the other table.

                    If you then go to another row in the portal and enter a value in the field,

                    the data doesn't get copied.

                    What I don't get is why , doing the same exact thing, except in a different

                    row in the portal, the data doesn't get copied..

                    BUT if you delete the records in the second table and try it again, the

                    data gets copied into the record the first time, then doesn't the second

                    time.. weird..

                     

                    This database is a supply_delivery app..

                    Requests for supply items are entered into the  dbf.

                    A person, then looks at the request in a portal and enters how many of each

                    item that was requested, will be delivered. This data is what I am copying

                    to the other table. I use it for a delivery slip..

                     

                     

                     

                    see attached...

                    • 7. Re: setfield works on first row in portal, but not the other rows
                      bigtom

                      Is the field you want to set in the portal row? Even if it is hidden behind another field having it on the layout and in the row makes it accessible.

                       

                      I will take a closer look in a few hours.

                      • 8. Re: setfield works on first row in portal, but not the other rows
                        user26728

                        I set three fields in the portal row. Invid, item and quantity.. ( see the

                        script ) .. G

                        • 9. Re: setfield works on first row in portal, but not the other rows
                          bigtom

                          Just because the field is set in the script does not mean that field is in the portal row. Just wanted to confirm.

                           

                          I will look closer in a few hours.

                           

                          If you have a demo file that would be helpful.

                          • 10. Re: setfield works on first row in portal, but not the other rows
                            electon

                            Does a record in the second table actually get created but comes up empty for other portal rows?

                            Or what you get is just the record created by the first portal row gets overwritten?

                            You can compare this if you have a modification timestamp field in the related table.

                             

                            If so then it may well be a context issue. And it's obscured because everything is linked to everything.

                            1) what is the parent layout table occurrence name?

                            2) what is the portal table occurrence name?

                            3) what is the table occurrence name where the data needs to be copied to?

                            • 12. Re: setfield works on first row in portal, but not the other rows
                              keywords

                              user26728 wrote:

                              It always works on the first row of the portal.

                              Then not on any of the other rows...

                              This is the giveaway—you have a context issue here. The fact that the first row of the portal is always chosen indicates the FM is defaulting to that row from outside the portal. If you want to script this process you must (1) give the portal an Object name; (2) in your script, navigate to the portal using Go to Object; (3) add a means of choosing an appropriate portal row (e.g. a counter variable); (4) use that counter to navigate to the appropriate portal row before posting the data.

                              The attached file demonstrates the above in action. If it helps point the way feel free to import the script and adapt it to suit your needs.

                              • 13. Re: setfield works on first row in portal, but not the other rows
                                electon

                                That may not be the case.

                                The script is triggered off of a field object that is on a portal and all it does is SetField in a table related to that portal ( so it seems ).

                                So the context ( the portal and active portal row ) is already established.

                                This will even be preserved when a button outside the portal is clicked and the related grandchild record should be accessible.

                                Unless there's a Commit Record happening somewhere in the script before SetField.

                                This will exit the portal and default the child record to the first record there is.

                                • 14. Re: setfield works on first row in portal, but not the other rows
                                  user26728

                                  thanks for looking at this.. I don't see your file attachment.. G

                                  1 2 Previous Next