12 Replies Latest reply on Dec 2, 2013 3:04 PM by keywords

    Navigate from one of many portals with same script


      So, I have a dashboard layout that shows 7 portals depicting current jobs on our various presses, each portal showing a different press. The graph TOG for the dashboard is something like this:


      Dashboard -- JobTickets (filtering to current tickets) -- Jobs (filtering the various presses) -- JobTickets (to show related records in the portal)


      So, there are 7 branches from the first JobTickets TO to Jobs, one for each press.


      I want an edit button on each line that will take the user to the JobTickets screen. On my other layouts, I just do this with a simple GTRR to the main JobTicket layout. However in this case, the Dashboard is it's own TOG, so nothing on the Dashboard layout is actually related to the main.


      My work-around was to have the script grab the primary key and then go to JobTickets and perform a find. But do I need 7 different scripts (or if/else branches within the script) to do this, since each portal is it's own TO? There must be some kind of Get function - perhaps that I can pass as a script param to get the TO name of the portal, that would then let me get that TO::[key_field] value. I'm just not getting the syntax of it all.


      Here is an example of the one of the fields that I want to get the value of:


      The part that is "240" is the part that will change for each portal.


      Many thanks on this Thanksgiving eve!


        • 1. Re: Navigate from one of many portals with same script



          Set Variable [ $ID ; GetField ( "Dashboard_JobTickets__2Press_Jobs__" & Get ( ScriptParameter ) & "_JOBTICKETS::__pk_JobTicket_ID" ) ]


          where the script parameter is specific to the portal, e.g. 240

          1 of 1 people found this helpful
          • 2. Re: Navigate from one of many portals with same script

            I had done some more putzing since my post and made some pretty good progress, but was still stuck on one last part. I think I'm on the verge of getting it to work without even needing to feed it a script parameter.  I was getting frustrated and didn't realize how late it had gotten, so forgive me if my memory is a little cloudy and I don't have the syntax quite right here. But, here is the basic idea of what I did.


            Go to Portal Row [Select; [perform without dialog]; Get(ActivePortalRowNumber)]

            Set Variable [ $PortalTO ; Value: GetLayoutObjectAttribute ( Get ( ActiveLayoutObjectName ) ; "source" ) ]

            Set Variable [ $JobTicketID ; Value: GetField ( $PortalTO & "::__pk_JobTicket_ID") ]


            Then, I try to do the find in the main JobTicket layout with the variable $JobTicketID. It finds nothing. In the data viewer, the variable $JobTicketID shows a value of: Dashboard_JobTickets__2Press_Jobs__240_JOBTICKETS::__pk_JobTicket_ID

            So, I'm getting the text of the field, but not the value. I tried wrapping the calc for that variable in Evaluate ( ), and a few other. In the data viewer, I either show a ? or the text of the field name I'm looking for.


            So close, but had to leave… and I don't have remote access. I thought that GetField would do the trick, and in your example, it looks like it should work as well. Do I have a quote in the wrong place or something?


            It will drive me nuts over the long weekend! 


            Happy Thanksgiving!


            • 3. Re: Navigate from one of many portals with same script

              Get ( LayoutObjectAttribute ) works with named objects, not fields per se, which means you'd have to give your fields different object names – and that's no progress compared to Script Parameters.


              But if you make a field in the portal enterable, you can use an OnObjectEnter trigger with


              Set Variable [ $PortalTO ; Value: Get ( ActiveFieldTableName ) ]

              Set Variable [ $JobTicketID ; Value: GetField ( $PortalTO & "::__pk_JobTicket_ID") ]


              Since you can Commit and then go off to your other table, the field isn't actually enterable, so you could use whatever field fits your idea of a "button"; if there is none, create a global in JobTickets, type in "Edit", add the trigger (and round the corners …) and place the correct versions into the respective portals. (Well, that's a sort of embedded parameter, but the information has to come from somewhere …)


              Happy Thanksgiving to you, too – this is not a holiday in Europe, but I appreciate the sentiment.

              • 4. Re: Navigate from one of many portals with same script

                Oh yeah, forgot to mention that in order to get what I had to work, I did have to give each Portal an object name. When you click the button, it selects the enclosing portal row, so it should work if the user is in a field or not.  But the cool thing is that it doesn't matter what the portal's object name is, just that it is named. I never need to reference the object name, so it seems a little more portable than a parameter to me.


                I'll have to take a look at my wording for that last Set Variable and see why it is returning the field name, rather than the value. Hopefully just a type-o somewhere in there.




                Sent from my iPhone

                • 5. Re: Navigate from one of many portals with same script

                  I think there is an easier way.


                  If you have a script trigger on a field within the portal, you can capture the not only the table name of the field that you've clicked into, but also the key ID field of the table (as long as the field name is the same in all tables, you can use evaluate).


                  If you name all your layouts to include the table name it beongs to, then what you can then do is NOT use go to related record, just simply goto layout by calculation, using the table name captured by the initial script trigger, then perform a find on the id (enter find mode, set field by name (table::id) then perform the find)...


                  Viola! you have essentially done a go to related record, without using the relationship. (error trapping and handling is recommended).


                  This, in my view, if much more flexible than GTRR and it can be adapted to multiple TOC's, as long as there is commonality in the layout and field naming.


                  I have used this tecnique in a solution I have created - it has one table acceccible via multiple other parent tables, as a well as mulptiple portals pointing to the one child table (you can include parameters in your scripts, of course).


                  PLUS, if you have specific fields in the portal that should show a different layout depending on the content, this is easier to control in the script.


                  I hope this helps...?

                  1 of 1 people found this helpful
                  • 6. Re: Navigate from one of many portals with same script

                    Firgured out my goof.


                    The script step:

                    Set Variable [ $JobTicketID ; Value: GetField ( $PortalTO & "::__pk_JobTicket_ID") ]


                    Should have been:

                    Set Variable [ $JobTicketID ; Value: GetField ( $PortalTO & "::_fk_JobTicket_ID") ]


                    My portal is based on the Jobs table, but I'm trying to send people to the [parent] JobTickets layout. So, there was no such field for GetField to evaluate, hence the "?" in the data viewer, and the null found set in the JobTickets layout.

                    It's amazing what a long weekend away and some turkey will do for you. 


                    Thanks again for all your help!


                    • 7. Re: Navigate from one of many portals with same script

                      Thanks for the input, Peter. However, in this case… my dashboard layout doesn't have many fields that can be entered into or edited on this layout. Just meant to give an overhead view of jobs in the pressroom. So, I really need it to be performed by a button, rather than a field. I found the error in my script, so I did get it working without any script triggers or parameters. It just figures out which portal the button is in, then grabs the key it needs to go to the desired layout and find the corresponding record there.


                      Another thought that I had over the weekend…

                      My original GTRR didn't work because my dashboard TOG isn't related to the TO layout that I want to go to. But I suppose one could relate them somewhere in the Dashboard TOG with a 1-to-1 relationship back to the main TOG with the destination layout. The drawback to this would be a spaghetti relationship graph, so I don't think I want to go there, now that I have it working. But there is always more than one way to skin the proverbial cat!




                      • 8. Re: Navigate from one of many portals with same script

                        I haven't put it to the test, but the approach suggested by Peter certainly sounds cleaner and simpler. You could use it if you simply create a utility field (call it 'navigate' or something) which you put in your portal and define with the OnObjectEnter script trigger as suggested; you could even format it to look like a button. This way you get the best of both—to the user it will look and behave like a button, but have the simpler operation suggested.

                        • 9. Re: Navigate from one of many portals with same script

                          Funny – exactly what I suggested in post #3.

                          • 11. Re: Navigate from one of many portals with same script

                            To each their own opinion, but in the end, I think the solution I found (The above one, not the new possibility I posted of adding a relationship and using GTRR) is easier.  Yes, I had some bumps getting there, but that was my own fault. With what I have now, my "edit" button is actually just a little pencil .png that I use throughout the interface, so my users recognize it as a way to go to a layout where they can edit more info. I don't have an extra field to be the button, and I don't have to use triggers that require a field. No need to make sure that the button field is the correct one. The portal has an object name (and it doesn't matter what that name is), that allows the GetLayoutObjectAttribute command to work. I can duplicate and move the button from one portal to another without having to change anything. The script figures out which portal it is in and goes from there. 


                            I'll take a little more coding up front, if it means that the result is more portable.


                            But I do love hearing about the many ways to get there. There will always be another problem that will find this info valuable down the road.


                            Thanks again.


                            • 12. Re: Navigate from one of many portals with same script

                              All sounds good Shawn. As is often stated on this forum, there are many ways to achieve a purpose with Filemaker—one of the things most developers enjoy about FM.