1 2 Previous Next 17 Replies Latest reply on Mar 5, 2017 4:57 PM by DrewTenenholz

    Starting my first custom function

    dbail22@comcast.net

      I am attempting to convert a script into a custom function but my lack of knowledge has me stumped.  Below is a simple function called by TopPortalRow(PortalName,FieldName,start). It tests a named field in a portal row of a named portal to see if the field (portal row) is below the top of the portal.  Works fine in a script and Loop-End Loop but not here.   I feel it is something simple in the last line but cannot figure it out.  An additional simple question is what value is returned in such a function. I was trying to make it n but not getting anywhere.  Thanks in advance for any help.

       

      David

       

       

      /* Calculate the top of the portal passed in the name  */

      Let (p = GetLayoutObjectAttribute(PortalName;"Top";"");

       

      /* Calculate the top of the specified portal row using a named field  */

      Let (r = GetLayoutObjectAttribute(FieldName;"Top";n);

       

      /* Test to see if r-top of portal row is greater than p-top of portal

           If not call the function again with n+1 or return with n  */

      Case(p>r;n;FirstPortalViewed(PortalName;FieldName;n+1))))

        • 1. Re: Starting my first custom function
          user19752

          1) portal row number is 4th parameter in GetLayoutObjectAttribute(), 3rd is repetition.

          2) logic is negated, it should be Case(p<r;n....

          1 of 1 people found this helpful
          • 2. Re: Starting my first custom function
            dbail22@comcast.net

            Thank you very much for the response.  I added an unused variable so the portal row was in the correct position.  Still no response from this function.

             

            /* Called with FirstPortalViewed(PortalName;FieldName;"";1)*/

             

            /* Inputs:

            PortalName = Name of the Portal - necessary for layoutinfo

             

            FieldName = Name of field used - necessary for layoutinfo

             

            x = (unused for repetition)

             

            n = which portal row to start with

            */

             

            /* Calculate the top of the portal passed in the PortalName  */

            Let (p = GetLayoutObjectAttribute(PortalName;"Top";"";"");

             

            /* Calculate the top of the specified portal row using the FieldName field  */

            Let (r = GetLayoutObjectAttribute(FieldName;"Top";"";n);

             

            /* Test to see if r (field top)is greater than p (portal top). If not call the function again with n+1 or return with n  */

            Case( r > p;n;FirstPortalViewed(PortalName;FieldName;n+1))))

            • 3. Re: Starting my first custom function
              siplus

              scripts and custom functions are 2 different worlds. Not interchangeable.

               

              Recursive custom functions are not the best thing to start your experience, either - hard to debug.

               

              What - and why - are you trying to do ?

              • 4. Re: Starting my first custom function
                dbail22@comcast.net

                Many interfaces I have for non-profits include managing and accessing large numbers of documents stored in remote containers. Most of the time a portal view of the basic information on a document is available to find a date, type, unit, name, and other items associated.  There are basic sorting things done to display from 200 to 1000 items instead of 200,000 in one case.  When you scroll to the middle of a list of 500 documents and select one to display, filemaker resets the portal list as it displays the image in a separate container. Most times users are interested in other documents displayed nearby by date, name, scan date, etc., but the selection is gone.  If you know the top portal row displayed when you click and the number of rows in the portal you can refresh the list back to where it was.  I have a script that does this very well but would like to create a function to be portable any were an a single solution or importable to other solutions.  The solutions have spread far and wide because of the interface. Thanks for the reply. 

                • 5. Re: Starting my first custom function
                  dbail22@comcast.net

                  Here is a small part of the script that I am trying to replicate in a custom function.

                   

                  Screen Shot 2017-03-03 at 11.51.03 AM.png

                  • 6. Re: Starting my first custom function
                    DavidKamar

                    Wouldn't it be much easier (an efficient) to simply save the active portal row they are selecting, and then navigate back to it?

                     

                    Have your select script save Get(ActivePortalRowNumber) into a global.

                    You can then scroll back to it by navigating to the named portal via Go To Object, Go To Portal Row [$$SavedPortalRow] and Go To Object[FieldName].

                     

                    A custom function that scrolls through the entire portal of records seems very inefficient.

                    • 7. Re: Starting my first custom function
                      dbail22@comcast.net

                      Goto $$SavedPortalRow would put the previous selected row at the bottom of the portal and not in its original position. If the active portal row was 25 and it was original located in the middle of the portal it would then be at the bottom of the portal. Very undesirable for users.

                      • 8. Re: Starting my first custom function
                        philmodjunk

                        When you scroll to the middle of a list of 500 documents and select one to display, filemaker resets the portal list as it displays the image in a separate container.

                         

                        Why allow the portal to scroll at all? It's possible to do this without the portal's scroll bar resetting.

                         

                        You can do either of the following and the portal scroll bar will not reset:

                         

                        1. Open a new window and display the data from the portal record in the new window. The user closes the window when done.
                        2. Open a popover and use it to display the same data.
                        • 9. Re: Starting my first custom function
                          dbail22@comcast.net

                          Thanks but too many scripts and screen flashes.  The fix was as simple as User15792 said. There needs to be 4 parameters in each call.  I missed the last call even though I looked at it a hundred times.  Thanks for the responses.  Here is the working function.

                           

                          /* Inputs:

                          PortalName = Name of the Portal - necessary for layoutinfo

                           

                          FieldName = Name of field used - necessary for layoutinfo

                           

                          x = not used. Function requires 4 parameters.

                           

                          n = which portal row to start with and counter for recursion

                          If the top field/portal row is only half visible then the returned portal row will be the first portal row that is completely below the top of the portal

                           

                          */

                           

                          /* Calculate the top of the portal passed in the PortalName  */

                          Let (p = GetLayoutObjectAttribute(PortalName;"Top";"";"");

                           

                          /* Calculate the top of the specified portal row using the FieldName field  */

                          Let (r = GetLayoutObjectAttribute(FieldName;"Top";"";n);

                           

                           

                          /* Test to see if r (field top)is greater than p (portal top). If not call the function again with n+1 or return with n */

                          Case( r > p ; n ; FirstPortalViewed(PortalName; FieldName; "";n+1))))

                          • 10. Re: Starting my first custom function
                            philmodjunk

                            On the contrary, no screen flashes--especially if using a popover and the scripting is not complex either.

                            • 11. Re: Starting my first custom function
                              dbail22@comcast.net

                              Thanks for the response but it works very well and has for many years.

                              • 12. Re: Starting my first custom function
                                philmodjunk

                                Yes it works I'm sure but "very well"? I'll have to politely disagree on that.

                                 

                                What you describe has what I consider "brittle" design elements. Simple layout modifications at some point in the future can "break" what you've designed such as by inadvertently losing or changing a layout object's object name. Losing and setting the focus (as needed to scroll the portal) can also trip script triggers so the simple act of adding a trigger to a portal element might also interfere.

                                 

                                In my book it's better not to have to restore object focus and scroll position if such can be gracefully avoided.  In what you describe here, that is usually something that can be achieved and in a fairly straight forward fashion.

                                1 of 1 people found this helpful
                                • 13. Re: Starting my first custom function
                                  dbail22@comcast.net

                                  So I will politely disagree with you.  You have no idea of the rest of the interface or the requirements.  This has worked on solutions with from 500 to over 200,000 records in many hundreds of installations in non profit animal rescue groups.  There is no problem restoring the focus since clicking on the portal row displays the desired image and is handled by a very simple script again used for many years.  I have been a programmer for over 50 years in so many languages it is amazing.  I am known for clean and well working interfaces and comments on a small snippet of code are unworthy of the time you have been here.  Please feel free to move on with such close minded comments on such trivial evidence.

                                  • 14. Re: Starting my first custom function
                                    siplus

                                    If somebody has to move on it's surely not philmodjunk . He's one of the biggest assets this forum - and the whole Filemaker community - has.

                                     

                                    Moreover, any comments on any snippet of code are valuable because a searchable forum will give answers years from now to people able to use the search button.

                                     

                                    Lastly, having a long list of programming languages you've been using for years to move your dataflows is sometimes a liability, not an asset. I speak from personal experience, having punched cards in Fortran and coded in assembler, Cobol, Lisp, Pascal, Modula-2, Ada etc and having had my fun on 255 char one-liners in Basic, too, like many members of this forum. It is a liability because back then what counted was not UX, it was solving a problem, but nowadays it's all about UX, and if you don't get it, if you're not able to bend your code to what mr. Joe Browser expects, you're just another potential candidate for Madame Trussaud's wax museum.

                                    1 2 Previous Next